I have a file in which more than 50,000 lines are there. How can I split the file into two or more based on the selected lines?
Suppose I want to split a file from line 10,000 to line 40,000.
I have a file in which more than 50,000 lines are there. How can I split the file into two or more based on the selected lines?
Suppose I want to split a file from line 10,000 to line 40,000.
Use awk
:
awk ' NR<=10000{ next}
NR<=40000{print > "out2.txt"; next} ' input.txt
awk 'NR > 10000 && NR <= 40000' input.txt > out2.txt
– Stéphane Chazelas
Aug 13 '14 at 16:07
print
statements. I should have edited properly or deleted the post really!
– garethTheRed
Aug 13 '14 at 17:21
If you want lines 1 to 9999 in one file, 10000 to 40000 in a second and the rest in a 3rd, you can use:
csplit -f file.out file.in 10000 40001
(will store in file.out0{0,1,2}
)
You can use sed:
sed -n '10000,40000p' <infile
sed '10000,$!d;40000q'
or tail -n +10000 | head -n 30001
to stop reading after the 40000th line.
– Stéphane Chazelas
Aug 13 '14 at 16:05
10000
to40000
and skip the rest? – cuonglm Aug 13 '14 at 15:38