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
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:
Otherwise, use shell variables to split it up a bit.
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.
Yes it can, just quote it as usual:
Regex isn't meant to use such long expression, why not shortcut the needle like this:
Sandra, you can alternatively put that large sed command in a file, say
tftp.sed
and invoke sed likesed -i -f tftp.sed /var/lib/tftpboot/ltsp/i386/pxelinux.cfg/default
wheretftp.sed
file looks like:As you can see above, you can have multiple sed commands inside the sed source file, just be sure they are each in a separate line.
This might work for you:
or
N.B. the
&
in the Right Hand Side of the substitution represents all of the matching regex on the Left Hand Side