Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

Need to sum up a column value from multiple files into Credit and Debit categories using awk comman.

$
0
0
i have multiple files with Batch Header, Record detail & Batch trailer data in the files like :
Code:

BH 20150225950050N8262
RD 20140918000000 99999999 unk Deferred Settlement -13950
BT01 -13950

*Above sample data donot have the spaces coorectly defined. I do have multiple batch trailer records in 1 file.*

Batch trailer holds the sum of data from all RD type records.(3 columns for Batch Trailer with 2,10,18 as column widths.)
I need to calculate the Sum of data in Batch Trailer from all files in Debit & CRedit category.
I tried below queries, but i donot get any output:
Code:

awk '{$1=='BT' && value=SUBSTR($1,13,30); if(value>0) {credit+=value}} END {print credit}' FIELDWIDTHS="2 10 18" AMT92015-02-25
 
awk ' {$0=='BT' &&
value=substr($0,13,30)
if(value>0) { plus+=value}
else {minus+=value}
}
END { print plus, minus} ' AMT*

Could you please help if i missed anything in my query.

Viewing all articles
Browse latest Browse all 16232

Trending Articles