このページの内容

このスクリプトは、「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
コード内の説明(日本語訳)

異なる行が見つかりました。その行をパターンスペースに残し、先頭へ戻って重複行を探します。