I\'m trying to add a line of text to the middle of a text file in a bash script. Specifically I\'m trying add a nameserver to my /etc/resolv.conf file. As it stands, resol
Assuming you want to insert immediately after the search line, this is much simpler:
sed -ie '/^search/a nameserver 127.0.0.1' filename
-i : edit file in place-e : allows the execution of a script/commands inside sed expressiona mynewtext : command that tells sed to insert the text mynewtext after matched pattern