我想要获取第一列重复的行(我使用数字 32,因为第一列始终有 32 个字符)。到目前为止我已经弄清楚:
sort | uniq -d -w 32 filename
问题是我想要两条线,而不仅仅是一条。例如来自:
283158c7da8c0ada74502794fa8745eb ubuntu-6.10-alternate-amd64.iso
5717dd795bfd74edc2e9e81d37394349 ubuntu-6.10-alternate-i386.iso
5717dd795bfd74edc2e9e81d37394349 ubuntu-6.10-alternate-powerpc.iso
我想要的输出是:
5717dd795bfd74edc2e9e81d37394349 ubuntu-6.10-alternate-i386.iso
5717dd795bfd74edc2e9e81d37394349 ubuntu-6.10-alternate-powerpc.iso
不是
5717dd795bfd74edc2e9e81d37394349 ubuntu-6.10-alternate-i386.iso
我得到的
答案1
尝试
... | awk '{if ($1 in used ) {
if (used[$1] != "" ) print used[$1] ;
print ;} else used[$1]=$0 ;} '
答案2
使用 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