grep or awk looking for repeating text

I am looking for a way to find the below pattern in text.

777777,111,08-20-2011 
111111,222,08-20-2011 
777777,111,07-24-2011
777777,222,07-24-2011 
111111,222,07-22-2011

I would like to find a way to print every line in a file where the first 6 numbers match and there is different entries in the second column on the same date.

This would be the output I need.

777777,111,07-24-2011
777777,222,07-24-2011 

[/FONT]

OK... this is not very elegant, but should work:

awk -F, 'a[$1,$3]++' input | sed 's/,[^,]*,/,.*,/' | uniq  | while read i ; do
   grep "$i" input 
done
awk -F, 'a[$1,$3]++' input

basically looks for duplicates, but doesn't print the first occurance, just the lines with first and thirs field already encountered. Then, the second field is taken out with sed, and the input file is greped for each pattern (1st and 3rd field with 2nd being whatever) .

Hi,

A solution using Perl:

$ cat infile
777777,111,08-20-2011 
111111,222,08-20-2011 
777777,111,07-24-2011
777777,222,07-24-2011 
111111,222,07-22-2011
$ cat script.pl
use warnings;
use strict;

my (%reg);
while ( <> ) {
        next if /^\s*$/;
        s/\s*$//;
        my @f = split /,/;
        push @{ $reg{ join( ",,", @f[0,2] ) } }, $f[1];
}

foreach my $key ( keys %reg ) {
        next unless @{ $reg{ $key } } > 1;
        my %seen;
        my @values = grep { not $seen{ $_ }++ } @{ $reg{ $key } };
        foreach (@values) { 
                printf "%s%s%s\n", $key =~ /^([^,]+,)/, $_, $key =~ /.*(,.*)$/;
        }
}
$ perl script.pl infile
777777,111,07-24-2011
777777,222,07-24-2011

Regards,
Birei

Not for sale:

cat INPUTFILE | sed 's/ *$//' | awk -F, '{ print $0, $3, $2, $1 }' | 
sort | uniq -f2 | sed -rn 'G; /(.{6})\n\1/p; s/\n.*//; h' | cut -d' ' -f1
777777,222,07-24-2011
777777,111,07-24-2011

And I know everything about cats. )))

How about if I want to see all users with multiple different entries in the second field? I would want all lines from those users.

input

777777,111,08-20-2011 
111111,222,08-20-2011
222222,222,08-11-2011 
777777,111,07-24-2011
777777,222,07-24-2011 
111111,222,07-22-2011
222222,111,07-29-2011

output

777777,111,08-20-2011 
222222,222,08-11-2011 
777777,111,07-24-2011
777777,222,07-24-2011 
222222,111,07-29-2011

I am learning a little at a time. This stuff is amazing!!!

If you don't bother about the order you can just remove my awful sed command from the filter.

Well, it gives the wrong result... (((

$
$
$ cat input
777777,111,08-20-2011
111111,222,08-20-2011
222222,222,08-11-2011
777777,111,07-24-2011
777777,222,07-24-2011
111111,222,07-22-2011
222222,111,07-29-2011
$
$
$ perl -F, -lane '@c = grep {defined $$_{$F[0]}} @x;
                  if (! defined @c) {
                    push @x, { $F[0], [$F[1], "$.:$_"] };
                  } else {
                    $c[0]->{$F[0]}->[0] .= ",$F[1]" if $c[0]->{$F[0]}->[0] !~ /$F[1]/;
                    push @{$c[0]->{$F[0]}}, "$.:$_";
                  }
                  END {
                    foreach $i (@x) {
                      @v = values %$i;
                      if (@{$v[0]}[0] =~ /,/) {
                        foreach (@{$v[0]}[1..$#{$v[0]}]) {
                          ($key, $val) = split /:/;
                          $z{$key} = $val;
                        }
                      }
                    }
                    print $z{$_} foreach (sort keys %z);
                  }
                 ' input
777777,111,08-20-2011
222222,222,08-11-2011
777777,111,07-24-2011
777777,222,07-24-2011
222222,111,07-29-2011
$
$

tyler_durden