Array Printing Inline
Dear friends ,
The output file of below script
Pls#!/bin/sh
awk '{
bo = substr($0,13,3)
slm = substr($0,150,8)
slo = substr($0,175,7)
inc = substr($0,97,10)/100
busi = substr($0,83,10)
mth = substr($0,39,2)
yer = substr($0,35,4)
printf"%3s:%8s:%7d:%10.2f:%10d:%.2d:%4d \n",bo,slm,slo,inc,busi,mth,yer
}' infile | sort -t: +6 -7 +5 -6 +2 -3n +1 -2d > tmpout
awk -F":" '{
br = $1
slm = $2
slo = $3
inc = $4
busi = $5
mth = $6
yer = $7
CTR[bo,slm,yer,mth] +=1
TINC[bo,slm,yer,mth] +=inc
BUS[bo,slm,yer,mth] +=busi
SLM [bo,slm,yer,mth] =slm
SLO1[bo,slm,yer,mth] =slo
MTH[bo,slm,yer,mth] =mth
YER[bo,slm,yer,mth] =yer
}
END {
for ( c in CTR)
printf" %.2d: %4d: %8s: %7d: %4d: %13.2f: %13d\n",MTH[c],YER[c],SLM[c],SLO1[c],CTR[c],TINC[c],BUS[c] | "sort -t: +3 -4n +2 -3d +1 -2 +0 -1"
}' tmpout > list.prt
------------------------------------------------------------------------
MTH YEAR SLM SLO CTR INCOME BUSINESS
================================================================
05: 2006: 0068683: 1234: 1: 940.00: 100000
06: 2006: 0068683: 1234: 2: 10094.00: 200000
07: 2006: 0068683: 1234: 1: 50000.00: 0
09: 2006: 0068683: 1234: 1: 677.00: 50000
11: 2006: 0068683: 1234: 1: 27109.00: 500000
12: 2006: 0068683: 1234: 1: 54800.00: 100000
01: 2007: 0068683: 1234: 5: 57596.00: 1300000
03: 2007: 0068683: 1234: 7: 87438.00: 1700000
05: 2007: 0068683: 1234: 1: 1251.00: 150000
06: 2007: 0068683: 1234: 2: 24844.00: 1000000
07: 2007: 0068683: 1234: 1: 10330.00: 200000
09: 2007: 0068683: 1234: 1: 1271.00: 150000
10: 2007: 0068683: 1234: 2: 13456.00: 1000000
02: 2008: 0068683: 1234: 2: 21603.00: 500000
03: 2008: 0068683: 1234: 12: 277414.00: 1900000
04: 2006: 0097883: 1234: 2: 50599.00: 65000
05: 2006: 0097883: 1234: 2: 21939.00: 125000
07: 2006: 0097883: 1234: 16: 200450.00: 35000
11: 2006: 0097883: 1234: 1: 2258.00: 50000
12: 2006: 0097883: 1234: 2: 32000.00: 0
03: 2007: 0097883: 1234: 29: 230000.00: 1615000
04: 2007: 0097883: 1234: 6: 52964.00: 550000
06: 2007: 0097883: 1234: 1: 2940.00: 50000
07: 2007: 0097883: 1234: 1: 10000.00: 0
08: 2007: 0097883: 2468: 6: 52384.00: 550000
-----------------------------------------------------------------------
The out put requires is
SLO ( Salesofficer) 1234
==========================================================
SLM (CY) 03/2006 04/2006 05/2006 06/2006 07/2006 08/2006 09/2006
---------------------------------------------------------------------------
0068683 000 000 100000 200000 000 000 50000
000 000 940.00 10094.00 50000 000 677.00
---------------------------------------------------------------------------
0097883 000 65000 125000 000 35000 000 000
000 50599 219339.00 000 200450.00 000 000
--------------------------------------------------------------------------
and likewise . on first line the month and year , on the second line SLM-ID
and continue with the business he has done and on the third line the incom
he has earned .where there is nothing will print 000( zero zero zero) .
Can you suggest what change I have to make in my script ??
The same is possible in perl ??
Thanks in advance .
Last edited by vakharia Mahesh; 05-20-2008 at 08:31 AM..