sed: uniq -d
1
1 7.18 Print Duplicated Lines of Input
1 ====================================
1
1 This script prints only duplicated lines, like 'uniq -d'.
1
1 #!/usr/bin/sed -nf
1
1 $b
1 N
1 /^\(.*\)\n\1$/ {
1 # Print the first of the duplicated lines
1 s/.*\n//
1 p
1
1 # Loop until we get a different line
1 :b
1 $b
1 N
1 /^\(.*\)\n\1$/ {
1 s/.*\n//
1 bb
1 }
1 }
1
1 # The last line cannot be followed by duplicates
1 $b
1
1 # Found a different one. Leave it alone in the pattern space
1 # and go back to the top, hunting its duplicates
1 D
1