using sed to insert line into file and overwrite the current file
hey there all
so what i need to do is insert a line (or couple of lines) into an existing file at a certain line number (say line 4).... sed by default write things to the standard output or to a file, i was hoping there was a way to overwrite the existing file... i dont want to write to some temporary file, then copy the temp file over the "live file" and then delete the temp file
so lets say my current file is called livefile.txt, i know i could do something like the following (i havent checked whether this works or not, but you'll get my meaning)
sed '4a\Line to insert' livefile.txt > templivefile.txt
then overwrite the live file with the updated tempfile, but i dont want to do this last step... i would like to simply change the livefile.txt without having to output to a temp file... is this even possible with sed?
any help would be greatly appreciated