SED – one liners

sed G
sed ‘s/.$//’ # assumes that all lines end with CR/LF
sed ‘s/^M$//’ # in bash/tcsh, press Ctrl-V then Ctrl-M
sed ‘s/\x0D$//’ # gsed 3.02.80, but top script is easier
sed “s/\r//” infile >outfile # UnxUtils sed v4.0.7 or higher
sed ‘s/^[ \t]*//’ # see note on ‘\t’ at end of file
sed ‘s/foo/bar/’ # replaces only 1st instance in a line
sed ‘s/foo/bar/4’ # replaces only 4th instance in a line
sed ‘s/foo/bar/g’ # replaces ALL instances in a line
sed ‘s/\(.*\)foo\(.*foo\)/\1bar\2/’ # replace the next-to-last case
sed ‘s/\(.*\)foo/\1bar/’ # replace only the last case
sed ‘/baz/s/foo/bar/g’



Subscribe for the latest posts, free promotions, and insider deals!!!