Moving or copying first rows and last rows into another file

Hi I would like to move the first 1000 rows of my file into an output file and then move the last 1000 rows into another output file.

Any help would be great

Thanks

see man head and man tail ...

head -n 1000 infile > outfile1
tail -n 1000 infile > outfile2
1 Like

also what if I move the middle 1000 (lets say row 45-1045) to a new file

sorry a bit more complicated then before

head -1000 > output1
tail -1000 > output2

see man sed ... sample below sets startline at 45 and endline at 1045 and then prints (p) both lines as well as all lines between them ...

sed -n "45,1045p" infile > outfile3
sed -n '45,1045p' infile > output3

For a large file, it's a good idea to add a quit command to those sed scripts so that they don't pointlessly read the rest of the file.

Regards,
Alister