sc2001
June 30, 2011, 6:26am
1
Hi Guys,
Greeting from Poland
I have a problem.
Using grep I list from file two information: IP and date
I want only uniqe IP and related with them date (first) on the output
awk -F" " '{print $1,$4}'|sort|uniq
dont work beacuse of not uniqe value $4 (date)
Please help me
Regards
Sc
awk '!a[$1]{a[$1]++;print $1,$4}' filename
There is an awk idiom to do that, (awk arrays can be indexed on anything similarly to Perl's hash constructs), however here's a Perl solution until someone comes along to remind us the correct way to do this in awk.
perl -e '
while(<>){
@record=split /\s/;
$firstUsed{$record[0]}=$record[4}if(!$firstUsed{$record[0]};
}
print "IP Address\tFirst Used\n","_"*80;
for (keys %firstUsed){
print "$_\t$firstUsed{$_}\n";' FILENAME
Update:And it's faster to type than the Perl solution, I must really invest some time in awk