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 c
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.
sedThe -i flag works differently on macOS sed than in GNU sed.
Here's the way to use it on macOS / OS X:
sed -i '' '8i\
8 This is Line 8' FILE
See man 1 sed for more info.
the awk answer
awk -v n=8 -v s="Project_Name=sowstest" 'NR == n {print s} {print}' file > file.new