Feeds:
文章
评论

Posts Tagged ‘sed’

sed -n ‘s/^.*\(<regex_pattern>\).*$/\1/p’ filename

This sed means substitute the whole line with the ‘\1’ (i.e. the matched pattern) and print the line. So it will print the text (not the whole line) which matches <regex_pattern>.

We can also use perl:   perl -i -p0e ‘s/abc\n efg/opq\n rst/’ filename

Advertisements

Read Full Post »

e.g.   sed -i ‘N; s/line1\n  line2/line1/’ /path/to/file

“N;” means multiline sed and “\n” means a NEW_LINE_CHAR

More example on http://www.thegeekstuff.com/2009/11/unix-sed-tutorial-multi-line-file-operation-with-6-practical-examples/

Read Full Post »