[prev] [index] [next]

sed: stream editor (cont)

More Examples:

# print only lines containing 'xyz'
sed -n -e '/xyz/p' < file

# print only lines not containing 'xyz'
sed -e '/xyz/d' < file

# show the passwd file, displaying only the
# lines from "root" up to "nobody" (i.e. system accounts)
sed -n -e '/^root/,/^nobody/p' /etc/passwd
 
# remove first column from ':'-separated file
sed -e 's/[^:]*://' datafile

# reverse the order of the first two columns
sed -e 's/\([^:]*\):\([^:]*\):\(.*\)$/\2:\1:\3/'