I am attempting to use (BSD) sed to modify my /etc/gettytab. The goal is to modify this entry:
P|Pc|Pc console:\
:ht:np:sp#9600:
to this entry:
P|Pc|Pc console:\
:ht:np:sp#115200:\
:cl=\E[H\E[2J:
If I issue the command below (it's on two lines), it works perfectly.
# sed -in ' /P|Pc|Pc console/,/^#/ s/9600:/115200:\\\\
:cl=\E[H\E[2J:/' /etc/gettytab
However, if I use the exact same command (literally copy/paste it) in a script, I get an error message:
sed: 1: " /P|Pc|Pc console/,/^#/ ...": unescaped newline inside substitute pattern
Searching, I found this post: unescaped newline inside substitute pattern which talks about the trailing /, but I have that in my pattern.
If anyone can assist with what I am doing wrong, I would greatly appreciate it.
Within your script, you escape newlines with a \, and you escape the \ that you're embedding into your output so that it will be interpreted literally. If my math is right, that comes to THREE, not four backslashes.
$ cat i
P|Pc|Pc console:\
:ht:np:sp#9600:
$ cat i.sh
#!/bin/sh
# ┏━━━ escapes the next character,
# ┃┏━━ literal backslash for output,
# ┃┃┏━ escapes the newline.
sed -ne '/^P|/,/^#/ s/9600:/115200:\\\
:cl=\E[H\E[2J:/' -e p i
$ ./i.sh
P|Pc|Pc console:\
:ht:np:sp#115200:\
:cl=E[HE[2J:
$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With