The UNIX and Linux Forums  

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 03-13-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,926

Code:
awk 'NR == 1 { print "lead1   07q4    07q1    06q4    06q3    sept    oct     nov     tot" }
$1 ~ "^("users")$" && NF > 1 { 
x[$1]++
if (x[$1] == 1) {
  p[$1] = sprintf ("%s\t%s\t%s\t%s\t%s", $1, $2, $5, $6, $7)
  t[$1] = $2 + $5
}
if (x[$1] == 3) {
  printf "%s\t%s\t%s\t%s\t%d\n", p[$1], $2, $3, $4, t[$1] 
 }
}' users="tim|tad" file