back toc next

sed commands

Eliminate comments

bash$ sed -e 's/#.*//' /etc/inetd

Eliminate comments and empty lines

bash$ sed -e 's/#.*//;/^$/d' /etc/inetd

Have a 133t prompt

bash$ ls -l | sed -e 's/o/0/;s/l/1/;s/e/3/'
bash$ ls -l | sed -e 's/o/0/g;s/l/1/g;s/e/3/g'
bash$ ls -l | sed -e 'y/ole/013/g'

Convert a file from DOS to UNIX and vice versa

 # Under UNIX: convert DOS newlines (CR/LF) to Unix format
bash$ sed 's/.$//' file # assumes that all lines end with CR/LF bash$ sed 's/^M$// file # in bash/tcsh, press Ctrl-V then Ctrl-M # Under DOS: convert Unix newlines (LF) to DOS format C:\> sed 's/$//' file # method 1 C:\> sed -n p file # method 2


Or use the utilities dos2unix and unix2dos, or the command
tr -d [^M] < inputfile > outputfile
for a conversion from DOS to UNIX, or
:set fileformat=dos
:set fileformat=unix
from within vim, or...