I have a huge text file. I want to extract the first 532541 lines of it and store them in another file. Selecting the text with the mouse and doing ctrl+c obviously is not a viable solution here.
How should I do this?
head
is the right tool for this job. With awk or sed, it's more efficient to quit processing the file after the target line, so the useless rest of the file does not have to be read.
sed '532541q' big > small
awk '{print} NR==532541 {exit}' big > small
awk 'NR<=532541' big > small
awk '{if(NR<=532541) print; else exit}' big > small #if the file is really huge
sed -n '1,532541p' big > small
sed '1,532541!d' big > small
sed '532542,$d' big > small
:) have fun