How do I add a line of text to the middle of a file using bash?

Here is a solution using sed: $ sed -n ‘H;${x;s/^\n//;s/nameserver .*$/nameserver 127.0.0.1\n&/;p;}’ resolv.conf # Generated by NetworkManager domain dhcp.example.com search dhcp.example.com nameserver 127.0.0.1 nameserver 10.0.0.1 nameserver 10.0.0.2 nameserver 10.0.0.3 How it works: first, suppress the output of sed with the -n flag. Then, for each line, we append the line to the hold space, separating … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)