I have searched and have found well-informed answers that I think should work, but I can't get them to work. The problem is that I clearly so don't understand sed and all of the slashes and what any of that has to do with regex. I think this is why I can't cross the bridge from very informative answers (such as sed: -e expression unknown option to `s') to making this work for me.
# WAN (Internet connection) auto wlp3s0 iface wlp3s0 inet dhcp dns-nameservers 22.214.171.124 126.96.36.199 wpa-conf /etc/wpa_supplicant_some1.conf #wpa-conf /etc/wpa_supplicant_oldstuff.conf
#!/bin/bash NEW_LINE="wp-conf /etc/wpa_supplicant_someother.conf" sed -i '/wpa-conf /c\'"$NEW_LINE" /etc/network/interfaces
The above kind of works. The entire line in the file that begins with wpa-conf is replaced with the new line in the script which is great.
But there is a nasty caveat: the commented wpa-conf line is also changed. This is what I'm trying to avoid. Reading the other answers, I've tried these in the script and a bunch of other hopeless variations that I could think of to no avail. These produce various errors:
sed -i '/^#/!s/wpa-conf /c\'"$NEW_LINE" /etc/network/interfaces sed -i '|^#|!s|wpa-conf /c\'"$NEW_LINE" /etc/network/interfaces sed -i '|^#|!s|wpa-conf |c\'"$NEW_LINE" /etc/network/interfaces
I clearly have no idea what I'm doing and I am evidently unable to understand how sed works and the other answers only made it worse for me.
All I'm trying to do is replace a line with another line as long as it isn't a line that is commented. The replacement line must be given in the form of a variable because it comes from other sources not shown here for brevity.
Regards and Thanks