Insert a line at specific line number with sed or awk

ashok picture ashok · Jun 30, 2011 · Viewed 209.2k times · Source

I have a script file which I need to modify with another script to insert a text at the 8th line.

String to insert: Project_Name=sowstest, into a file called start.

I tried to use awk and sed, but my command is getting garbled.

Answer

user unknown picture user unknown · Jun 30, 2011
sed -i '8i8 This is Line 8' FILE

inserts at line 8

8 This is Line 8

into file FILE

-i does the modification directly to file FILE, no output to stdout, as mentioned in the comments by glenn jackman.