このスクリプトは、「uniq -d」と同様に、重複する行だけを出力します。
#!/usr/bin/sed -nf
$b
N
/^\(.*\)\n\1$/ {
# Print the first of the duplicated lines
s/.*\n//
p
重複する行の最初の行を出力します。
# Loop until we get a different line
:b
$b
N
/^\(.*\)\n\1$/ {
s/.*\n//
bb
}
}
異なる行が現れるまでループします。
# The last line cannot be followed by duplicates $b
最終行の後に重複行が続くことはありません。
# Found a different one. Leave it alone in the pattern space # and go back to the top, hunting its duplicates D
異なる行が見つかりました。その行をパターンスペースに残し、先頭へ戻って重複行を探します。