[linux] How to copy the first few lines of a giant file, and add a line of text at the end of it using some Linux commands?

How do I copy the first few lines of a giant file and add a line of text at the end of it, using some Linux commands?

This question is related to linux

The answer is


I am assuming what you are trying to achieve is to insert a line after the first few lines of of a textfile.

head -n10 file.txt >> newfile.txt
echo "your line >> newfile.txt
tail -n +10 file.txt >> newfile.txt

If you don't want to rest of the lines from the file, just skip the tail part.


First few lines: man head.

Append lines: use the >> operator (?) in Bash:

echo 'This goes at the end of the file' >> file