I need to insert a command "new file" in a test.txt file at line number 4.
Tried sed; I can see the changed file output, but when I again do cat test.txt, the changes are gone.
sed "4i new file" /test.txt
How can I save the changes?
I need to insert a command "new file" in a test.txt file at line number 4.
Tried sed; I can see the changed file output, but when I again do cat test.txt, the changes are gone.
sed "4i new file" /test.txt
How can I save the changes?
 
    
     
    
    Use in place edit option sed -i "4i new file" test.txt
Without the -i option sed will not make any changes to the file. It will only print the result. 
-i[SUFFIX], --in-place[=SUFFIX]
    edit files in place (makes backup if SUFFIX supplied)
