A sed (stream editor) command consists of a range, the command name (a single letter), and arguments if apropriate. If the range is absent the command operates on all input lines. By default sed writes all input lines to STDOUT. All sed commands should be quoted to prevent special characters from being interpreted by the shell.
A few sed options:
-e-f-n-rA few sed range specifiers:
/regexp//regexp/!/regexp1/,/regexp2/A few sed command forms:
s/regexp/string/s/regexp/string/ns/regexp/string/gdphead -n25 /etc/passwd | sed -e 's/shutdown//' # delete 1st shutdown
head -n25 /etc/passwd | sed -e 's/shutdown/XX/' # change 1st shutdown to XX
head -n25 /etc/passwd | sed -e 's/shutdown/XX/2' # change 2nd shutdown
head -n25 /etc/passwd | sed -e 's/shutdown/XX/g' # every shutdown
head -n25 /etc/passwd | sed -e 's/shutdown/XX/g' -e 's/:/#/g' # two edits
head -n25 /etc/passwd | sed -e '/false$/s/:/#/g' # only lines ending false
head -n25 /etc/passwd | sed -e '/false$/!s/:/#/g' # lines not ending false
head -n25 /etc/passwd | sed -e '/^lp:/,/^ftp:/s/:/#/g' # range of lines
head -n25 /etc/passwd | sed -e '/^lp:/,/^ftp:/d' # delete range of lines
touch F1.old F2.old F3.old # create three files
ls F[123].*
ls F[123].* | sed -e 's/\.old$/.new/' # change extensions .old to .new
ls F[123].* | sed -e 'p' -e 's/\.old$/.new/' # also print original names
# next line passes the list of arguments to mv, no more than 2 at a time
ls F[123].* | sed -e 'p' -e 's/\.old$/.new/' | xargs -n2 mv
ls F[123].* # files are renamed
rm F[123] # clean up