views:

172

answers:

1

I want to split a 400k line long log file from a particular line number.

For this question, lets make this an arbitrary number 300k.

Is there a linux function that allows me to do this?

I know split lets me split the file in equal parts either by size or line numbers but that's not what I want. I want to the first 300k in one file and the last 100k in the second file.

Any help would be appreciated. Thanks!

On second thoughts this would be more suited to the superuser or serverfault site.

+5  A: 

line count (N): wc -l file_name

top of file (first K lines): head -n K file_name > top_file

bottom of file (L=N-K): tail -n L file_name > bottom_file

Also, on second thought, split will work in your case, since the first split is larger than the second. Split puts the balance of the input into the last split, so

split -l 300000 file_name

will output xaa with 300k lines and xab with 100k lines, for an input with 400k lines.

academicRobot
Thanks. found a similarly answered question over at superuserie. use tail etcAnd, yes split will work with my example, but not always had my example been 100K.
superspace