Monday, January 26, 2009

sed: some substitute text examples

Substitute text1 with text2 in file /etc/apt/sources.list:
cat /etc/apt/sources.list | sed 's/text1/text2/g' > out.txt
or with different 'slash':cat /etc/apt/sources.list | sed 's|text1|text2|g' > out.txt
Multiple substitution: cat /etc/apt/sources.list | sed -e 's/text1/text2/g' -e 's/text3/text4/g' > out.txt

Delete lines containing 'blabla' string:cat some.txt | sed -e '/blabla/d' > out.txt