SED delete, print and grouping
SED delete
A useful command that deletes line that matches the restriction: "d." For example, if you want to chop off the header of a mail message, which is everything up to the first blank line, use:
$ sed '1,/^$/d' file
SED print
If sed was not started with an "-n"
option, the "p"
command will duplicate the input.
sed '/^$/ p' file
Adding the “-n
” option turns off printing unless you request it.
SED grouping
The curly braces, "{"
and "}"
are used to group the commands.
Previously, we have showed you how to remove comments starting with a "#."
If you wanted to restrict the removal to lines between special "begin"
and "end"
key words, we use:
sed -n '
/begin/,/end/ {
s/#.*//
s/[ ^I]*$//
/^$/ d
p
}
' file
Get hands-on with 1400+ tech skills courses.