DEV Community

chanduthedev
chanduthedev

Posted on

2

Best way to add line numbers to the large file!!

Recently I started working on Machine Learning project. So started working on large uncleaned data files to clean and learned one of this tip today.

To add line numbers to large file just run below command on the file.


cat -n  file_name >new_file_name

Enter fullscreen mode Exit fullscreen mode

Above command will add the line number at the start of each line from file_name separated by tab and store in new_file_name without effecting the content of the file file_name.

If you want to replace tab with any character like comma, pipe(|) etc. Run below command.


cat -n  file_name | sed 's/\t/\,/g' >new_file_name

Enter fullscreen mode Exit fullscreen mode

OR


cat -n  file_name | tr '\\t' ',' >new_file_name

Enter fullscreen mode Exit fullscreen mode

Some times Mac systems may not identify tab(\t). Press Cntrl + V and press tab to identify tab key in Mac.

Warp.dev image

Warp is the highest-rated coding agent—proven by benchmarks.

Warp outperforms every other coding agent on the market, and gives you full control over which model you use. Get started now for free, or upgrade and unlock 2.5x AI credits on Warp's paid plans.

Download Warp

Top comments (0)