Solved Unix copy - using line numbers - how?

October 22, 2010 at 12:28:07
Specs: UNIX - AIX
Is there a way to copy a file in Unix by specifying which lines to copy? I know I can tail, etc.
but my file is so large - I want to break it into several smaller files and it is too large for vi.
Can I copy say - lines 1 thru 10,000 from fileA to fileB ? then copy lines 10,001 thru 20,000 from fileA to fileC ? etc?

See More: Unix copy - using line numbers - how?

Report •

October 22, 2010 at 17:36:36
you can use split. man split for more info

GNU win32 packages | Gawk

Report •

October 22, 2010 at 17:56:06
✔ Best Answer
In addition to split, you can try sed. This copies lines 8 to 13 in a new file:

sed -n '8,13p' datafile.txt > newfile.txt

I must admit that I have never tried sed on files as large as what you are talking about.

Report •

October 25, 2010 at 09:08:39
This worked - thank you very much!

Report •

Related Solutions

October 26, 2010 at 03:00:13
nails gave you a great solution. Just for your general information, I posted a short discussion about opening large files in vi. You might want to read this:

Jerry Lemieux

Report •

Ask Question