次: , 前: uniq, 上: Examples


4.15 入力の重複している行を出力する.

以下のスクリプトは,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