LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Adding lines of text to beginning of a text file (http://www.linuxquestions.org/questions/programming-9/adding-lines-of-text-to-beginning-of-a-text-file-698337/)

BillKat 01-19-2009 10:06 AM

Adding lines of text to beginning of a text file
 
Hi folks,

I need to insert 3-4 lines of text to the beginning of a text file. The file is a largish MYSQL dump, the result of a backup shell script. This shell script should insert the required text.

I've wrestled with sed, but lost ... Any ideas would be much appreciated, cheers.

colucix 01-19-2009 11:08 AM

There are a lot of ways to do that. A sed command is 'i' which stats for insert a new line before the pattern. Specify only the first line as address and the trick is done:
Code:

sed -i.bak '1i text to add' file

BillKat 01-19-2009 11:40 AM

Thanks for that, job done.


All times are GMT -5. The time now is 04:42 AM.