1

I want to get lines where first column duplicates (I used number 32 becouse first column has always 32 characters). So far I've figured out:

sort | uniq -d -w 32 filename

The problem is that I want both lines, not only one. For example from:

283158c7da8c0ada74502794fa8745eb  ubuntu-6.10-alternate-amd64.iso
5717dd795bfd74edc2e9e81d37394349  ubuntu-6.10-alternate-i386.iso
5717dd795bfd74edc2e9e81d37394349  ubuntu-6.10-alternate-powerpc.iso

The output I want is:

5717dd795bfd74edc2e9e81d37394349  ubuntu-6.10-alternate-i386.iso
5717dd795bfd74edc2e9e81d37394349  ubuntu-6.10-alternate-powerpc.iso

Not

5717dd795bfd74edc2e9e81d37394349  ubuntu-6.10-alternate-i386.iso

Which I get

  • 1
    Does uniq -D instead of uniq -d help? – iruvar Nov 12 '15 at 11:17
3

try

 ... | awk '{if ($1 in used ) {
               if (used[$1] != "" ) print used[$1] ;
               print ;} else used[$1]=$0 ;} '
0

Using Perl:

[...] | perl -lane 'grep(@F[1], @x)?print:push(@x, @F[1])'
% cat in
283158c7da8c0ada74502794fa8745eb  ubuntu-6.10-alternate-amd64.iso
5717dd795bfd74edc2e9e81d37394349  ubuntu-6.10-alternate-i386.iso
5717dd795bfd74edc2e9e81d37394349  ubuntu-6.10-alternate-powerpc.iso
% cat in | perl -lane 'grep(@F[1], @x)?print:push(@x, @F[1])'
5717dd795bfd74edc2e9e81d37394349  ubuntu-6.10-alternate-i386.iso
5717dd795bfd74edc2e9e81d37394349  ubuntu-6.10-alternate-powerpc.iso

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.