I am trying to write a sed expression to detect lines similar to this:s0:12345:respawn:/sbin/agetty -8 -s 115200 ttyS0 linuxand replace the ttys0 with something_elseI do not want to detect commented out lines (beginning with #)I can replace the whole line, but how to I just replace the substring, leaving the rest of the line intact ?
with sed, how can I replace word within a matching line?
sed;regular expression
One way to do this is as follows:echo 's0:12345:respawn:/sbin/agetty -8 -s 115200 ttyS0 linux' |     sed -e '/^[^#]/ s/ttyS0/foo/'