The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #5 (permalink)  
Old 09-02-2008
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,873
Just guessing:
(use nawk or /usr/xpg4/bin/awk on Solaris)

Code:
awk 'END \
{ for (dt in third) print dt, second[dt], third[dt] }
{ if (!_[$1]++) third[$1] = $3; second[$1] += $2 }
' filename
If you need the output sorted, pipe it to sort (or use asorti if you have GNU Awk). Or just use Perl

Code:
perl -ane'
  $third{$F[0]} = $F[2] unless $x{$F[0]}++;
  $second{$F[0]} += $F[1];
  print map "$_ $second{$_} $third{$_}\n", sort keys %x
    if eof' filename

Last edited by radoulov; 09-02-2008 at 07:22 AM..