редактор потока (stream editor)
Примеры (Examples)
This sed script simulates the BSD cat -s
command, squeezing
excess empty lines from standard input.
sed -n '
# Write non-empty lines.
/./ {
p
d
}
# Write a single empty line, then look for more empty lines.
/^$/ p
# Get next line, discard the held <newline> (empty line),
# and look for more empty lines.
:Empty
/^$/ {
N
s/.//
b Empty
}
# Write the non-empty line before going back to search
# for the first in a set of empty lines.
p
'
The following sed command is a much simpler method of squeezing
empty lines, although it is not quite the same as cat -s
since it
removes any initial empty lines:
sed -n '/./,/^$/p'