以下は,N
,P
,そしてD
コマンドを使用した,おそらく
マスターするのが最も難しい芸術的な例です.
#!/usr/bin/sed -f
h
:b
# On the last line, print and exit
$b
N
/^\(.*\)\n\1$/ {
# The two lines are identical. Undo the effect of
# the n command.
g
bb
}
# If the N
command had added the last line, print and exit
$b
# The lines are different; print the first and go
# back working on the second.
P
D
御覧のように,P
とD
を使用して二行のウィンドウを管理してい
ます.このテクニックは,高度なsedスクリプトでよく使用されます.