Tag Info

New answers tagged


If your sort can do a stable sort, e.g. GNU sort with the -s or --stable option, lines with fields unrelated to the sort keys will not be sorted by those fields when there are ties, but will stay in their same relative positions. $ sort -n -t. -k1,1 -k2,2 -k3,3 -k4,4 | uniq -c | sort -n -r -s 5 2 2 2 ...


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])' ...


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


From the uniq manpage: DESCRIPTION Discard all but one of successive identical lines from INPUT (or standard input), writing to OUTPUT (or standard output). Here the critical word is "successive". It doesn't search for duplicates at any point in the stream, only those that immediately follow. Sorting forces all duplicates to be next to each other, ...

Top 50 recent answers are included