Difference between revisions of "sed sed"

From Noah.org
Jump to navigationJump to search
Line 1: Line 1:
 +
[[Category:Engineering]]
 
=== find part of a line, substitute, keep rest of time intact ===
 
=== find part of a line, substitute, keep rest of time intact ===
 
   sed -i -e "s/^#DatabaseDirectory \(.*\)/DatabaseDirectory \\1/" myfile.txt
 
   sed -i -e "s/^#DatabaseDirectory \(.*\)/DatabaseDirectory \\1/" myfile.txt

Revision as of 16:33, 5 February 2007

find part of a line, substitute, keep rest of time intact

 sed -i -e "s/^#DatabaseDirectory \(.*\)/DatabaseDirectory \\1/" myfile.txt

find pattern in a line, insert new line before it

This finds line that begins with exit(ignore leading spaces), then insert 'authdarmond start' before it.

 sed -i -e "/^\\s*exit/i/authdaemond start" /etc/rc.local;

find pattern and append line

Note how replace pattern spans multiple lines

sed -i -e '/#!\/bin\/sh/a\
QMAILQUEUE="/var/qmail/bin/qmail-scanner-queue.pl" ; export QMAILQUEUE' /var/qmail/supervise/qmail-smtpd/run