I have sed
command that is very long
sed -i 's/append ro initrd=initrd.img quiet splash nbdport=2000/append ro initrd=initrd.img quiet splash nbdport=2000 video=LVDS-1:d/g' /var/lib/tftpboot/ltsp/i386/pxelinux.cfg/default
Can it be broken over several lines to make it more clear what it does?
E.g. something like?
sed -i 's/
append ro initrd=initrd.img quiet splash nbdport=2000
/
append ro initrd=initrd.img quiet splash nbdport=2000 video=LVDS-1:d
/g'
/var/lib/tftpboot/ltsp/i386/pxelinux.cfg/default
sed 's/[long1][long2]/[long3][long4]/' file.txt
you can use the usual backslash for spreading the expression on multiple lines. It is important though that the lines following a backslash do not feature a space at the beginning.
sed 's'/\
'[long1]'\
'[long2]'\
'/'\
'[long3]'\
'[long4]'\
'/' file.txt
A couple of ways you can make this smaller. If you are just appending the text to the end of the line, you can use sed like this:
sed -i '/append ro initrd=initrd.img quiet splash nbdport=2000/s/$/ video=LVDS-1:d' ...
Otherwise, use shell variables to split it up a bit.
PXE_BOOT_FILE=/var/lib/tftpboot/ltsp/i386/pxelinux.cfg/default
SEARCH_PATTERN='append ro initrd=initrd.img quiet splash nbdport=2000'
REPLACE_PATTERN="$SEARCH_PATTERN video=LVDS-1:d"
sed -i "s/$SEARCH_PATTERN/$REPLACE_PATTERN/g" "$PXE_BOOT_FILE"
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