=== Examples If you want to delete some line with word //word in line deleted//, use the following command: {{{ sed -i '/word in line deleted/d' filename }}} If you want to delete all CONSECUTIVE blank lines from file except the first; also deletes all blank lines from top and end of file, use command {{{ sed '/./,/^$/!d' filename # method 1, allows 0 blanks at top, 1 at EOF sed '/^$/N;/\n$/D' filename # method 2, allows 1 blank at top, 0 at EOF }}} Print matched line number, use {{{ sed -n '/word matching/ =' filename }}} Primt line content, use {{{ sed -n -e '/word matching/p' filename sed -n -e '3p' filename sed -n -e '3,5p' -e '8,9p' filename }}} Print all gnome* processes PID {{{ ps -A | grep gnome | sed -n 's/^s*\([0-9]*\)[^0-9]*/1/p' }}} Display total number of lines in file {{{ wc -l filename | sed -n 's/^s*\([0-9]*\)[^0-9]*/1/p' }}} === sed regular expression If we need to use either one of {{{ { } + ? ( ) | }}} in your sed editor command, you need to escape them, i.e. type {{{ \{ \} \+ \? \( \) \| }}} see more on [[http://www.gnu.org/software/sed/manual/html_node/Regular-Expressions.html#Regular-Expressions|sed regular expressions]] === Reference: #[[http://www.grymoire.com/Unix/Sed.html|Sed - An Introduction and Tutorial by Bruce Barnett]] #[[http://www.pement.org/sed/sed1line.txt|Sed one line command]] #[[http://edcsteel.com/sed_tutorial.html|sed tutorial]] #[[http://www.gnu.org/software/sed/manual/html_node/Regular-Expressions.html#Regular-Expressions|sed regular expressions]] #[[http://www.pement.org/sed/sed1line.txt|Useful one line script for SED]]