Sed Tutorials

A nice collection of Sed Tutorials. For example:

-- To align all text flush right on a 79-column width
sed -e :a -e 's/^.\{1,78\}$/ &/;ta'  # set at 78 plus 1 space

-- delete duplicate lines from a sorted file (emulates "uniq"). First
-- line in a set of duplicate lines is kept, the rest are deleted
sed '$!N; /^\(.*\)\n\1$/!P; D'

-- remove most HTML tags (accommodates multiple-line tags)
sed -e :a -e 's/< [^<]*>/ /g;/</{N;s/\n/ /;ba;}'

-- delete BOTH leading and trailing whitespace from each line
sed 's/^[ \t]*//;s/[ \t]*$//'

Leave a comment

Your comment