How to insert or add new line in a file using shell (sh) script in linux

by rajesh 2012-03-12 09:27:42

Hi All,

To add a new line in to an existing file can be done easily in linux using a command sed

sed '45i\newline here' filename


The above command will insert "newline here" on the 45th line in the contents of the filename and print the result as output.

We can redirect the output to a temp file and then mv it back as old file


sed '45i\newline here' filename > tempfilename
mv -f tempfile filename


2303
like
0
dislike
0
mail
flag

You must LOGIN to add comments