Array Printing Inline


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Array Printing Inline
# 1  
Old 05-12-2008
Question 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..
# 2  
Old 05-20-2008
The a2p script which ships with Perl can convert many awk scripts to Perl, although the result is not always pretty. The answer to "possible in Perl" would be "yes" in any event; anything awk can do, Perl can do too. (Computer science has a formal proof but I expect you don't want it.)
# 3  
Old 05-21-2008
Data array printing

Thanks Era for your reply , that did not give me the desired result
, have also tried with pr -a 3 ( i.e. printing accross ) you must be
well aware but that too failed. So I have great hope that there are
Gurus at this site will surely have some solution , I was waiting for
that .Anyway thanks lot . I think the matter is closed now.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Awk_ printing non-match in the array

Dear developpers, I intend to compare the file1 to the file2 based on the values of column 1 in file1. However, the current code - that I modified from the forum- only print matches. I am wondering if there is a solution to have both matches and non matches being printed. Many thanks in advance... (4 Replies)
Discussion started by: arsalane
4 Replies

2. Shell Programming and Scripting

Array not printing values if used in a loop

Hello! I'm making an English to Morse Code translator and I was able to mostly get it all working by looking through older posts here; however, I have one small problem. When I run it it's just printing spaces for where the characters should be. It runs the right amount of times, and if I try... (3 Replies)
Discussion started by: arcoleman10
3 Replies

3. Shell Programming and Scripting

Printing array elements in reverse

Hello Experts, I am trying to print an array in reverse. Input : 1. Number of array elements 2. The array. Eg: 4 1 2 3 4 Expected Output (elements separated by a space) : 4 3 2 1 My Code : (6 Replies)
Discussion started by: H squared
6 Replies

4. Shell Programming and Scripting

awk command hash array not printing

I'm new to awk command. The HASH ARRAY is not printing. Merging 2 files togather. vault_input.txt 3P04_Dep_Inxml:2230 REM02_Dep_Inxml:2200 REM03_Dep_Inxml:2400 REM05:2200 REM06:2200 tst6.txt Nov:10:2115:3P04_Dep_Inxml Nov:10:2129:REM02_Dep_Inxml Nov:10:2235:REM03_Dep_Inxml... (5 Replies)
Discussion started by: Sanj123
5 Replies

5. Shell Programming and Scripting

Variable substitution in array printing

Hi folks, A really dumb question as I've wasted far too long trying to get this to work.... (on RH bash) I have an array: m0='<hello>' m0='<there>' m0='<fred>' v0='<goodbye>' v0='<again>' v0='<john>' in my code I calculate the value of the variable to output and if I echo it, I... (2 Replies)
Discussion started by: say170
2 Replies

6. UNIX for Dummies Questions & Answers

printing array elements

Is there a way to print multiple array elements without iterating through the array using bash? Can you do something like... echo ${array}and get all those separate elements from the array? (2 Replies)
Discussion started by: jrymer
2 Replies

7. UNIX for Dummies Questions & Answers

Help with printing sorted array of numbers

Dear All, I am trying to sort an array of numbers to retrieve the mimimum and maximum values of numbers in that array, by printing the first and last elements of the sorted array. My code is @sorted_numbers = sort (@numbers); print "@sorted_numbers\n"; print "$sorted_numbers,... (0 Replies)
Discussion started by: pawannoel
0 Replies

8. Shell Programming and Scripting

printing array elements inside AWK

i just want to dump my array and see if it contains the values i am expecting. It should print as follows, ignore=345fht ignore=rthfg56 . . . ignore=49568g Here is the code. Is this even possible to do? please help termReport.pl < $4 | dos2ux | head -2000 | awk ' BEGIN... (0 Replies)
Discussion started by: usustarr
0 Replies

9. Shell Programming and Scripting

Perl - Problems iwith colors while printing from dynamic array at runtime..

Hi Perl folks, I am having problems printing elements from an array at runtime. I wish to push elements into array at runtime and the print it later. Now I wish to print this matrix using colors. So I do something like this to enter the runtime values in array: ... (1 Reply)
Discussion started by: som.nitk
1 Replies

10. Programming

printing all array values using dbx 7.2.1

how do we print the entire contents of arrays in dbx ? Ive tried using print x to print values 1 to 5 of the array x, however dbx complains and doesnt allow this help is much appreciated (1 Reply)
Discussion started by: JamesGoh
1 Replies
Login or Register to Ask a Question