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 -->
  #7 (permalink)  
Old 04-23-2009
gehlnar gehlnar is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 47
vgersh,

Step 1 :Initial File Conversion for basic calculation

Code:
cat INPUTFILE |tr -d '\015'|sort -k1,2|nawk -F'|' 
'BEGIN {OFS="~"}!/^PL/{next}$2=="L" && $3=="L"
{$4=0-$4};$6=="COM"?$6="SHS":$6="FMT"{print $0}'>TEMPFILE

Step 2: Actual calculation to get expected output using above's output of TEMPFILE

Code:
 awk -F'~' '{OFS="~"}{arr[$1OFS$5OFS$6]+=$4} END 
  {for (i in arr) {print i,arr[i]}}'<TEMPFILE>EXPECTEDFILE

I am using above mentioned two steps in a script , Hope you got some idea from it and my idea was to combine
these two steps into one.

Cheers,
gehlnar