Thursday, September 13, 2012

Insert a line at start of file in Linux

Adding a line at the end of file is very simple in Linux with the '>>' redirector. But adding a line at the beginning of the file entails the use of 'sed'. Suppose we have a file lines.txt:


If we want to add 'aaa' at the beginning we can use the following command:

sed -i '1i aaa' lines.txt
Post a Comment