How to file split at a line number [closed] How to file split at a line number [closed] shell shell

How to file split at a line number [closed]


file_name=test.log# set first K lines:K=1000# line count (N): N=$(wc -l < $file_name)# length of the bottom file:L=$(( $N - $K ))# create the top of file: head -n $K $file_name > top_$file_name# create bottom of file: tail -n $L $file_name > bottom_$file_name

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.