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




Thread: Output File
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 06-25-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
nawk -f char.awk fileFROMscript fileWithAllAccounts

char.awk:
Code:
# for the FIRST file specified on the command line....
# build array 'arr' indexed by the values from the SECOND column AND 
# the accumulated values from the FIRST column.
FNR==NR {arr[$2] += $1; next }

# for the SECOND file specified on the command line......
# print every record.
# if the value of the FIRST column appears as the INDEX in 'arr' - print the 
# 'value' from 'arr'. Otherwise print '0' .
{
   printf("%d%s%s\n", ($1 in arr) ? arr[$1] : 0, OFS, $1)
}

Last edited by vgersh99; 06-26-2006 at 02:41 PM..