Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert colums in rows 1

Status
Not open for further replies.

malpa

Technical User
Feb 8, 2004
122
CO
Thanks for your assistant.

This is my script, i want to obtain reports each half hour from file ope.log

My program LstToCsv2.awk
-----------------------
###first report
{
if(($1==1)&&(NF==7))
{
fecha=$6
hora=$7
print "first report"
opcion=1
}
if ((opcion==1)&&(NF==8)&&($1!="OG"))
{

printf"%s\t,%s\t\t,%s,%s,%s,%s,%s,%s,%s,%s\n",fecha,hora,$1,$2,$3,$4,$5,$6,$7,$8
{
###second report
if(($1==3)&&(NF==7))
{
fecha=$6
hora=$7
print "second report"
opcion=3
}
if((opcion==3)&&(NF==4)&&($1!="DEMAND"))
{
max_nf=NF
printf"%s\t,%s\t\t,", fecha,hora
for(i=1;i<=NF;i++)
{
nums[i,NR]=$i
printf "%s\t",nums[i,NR]
}
}
}
$1 ~ /END/{
for(x=1;x<=max_nf;x++){
printf "%s\t,%s\t\t,",fecha,hora
for(y=1;y<=NR;y++){
if(nums[x,y]!=""){
printf "%s\t\t,",nums[x,y]
}
}
print "\n"
}
}

file ope.log produce by a machine each half hour in the same file.
------------
#### begin first report
WO BOGOCEN CO24/1/ AT-5 TIME 040615 0928 PAGE 1
OPERATOR TRAFFIC RECORDING RESULTS 01

TRG MP NRP RPL RPN DATE TIME
1 8 12 30 7 040615 0900


OG ANO AT1PC AT2PC MTA HNO ALPVAL AUNB

GCNAL 353 98 100 3 168 79 14
GR192 259 95 100 3 123 89 11
GRCOD 37 78 86 8 22 78 2
##end first report
##begin second report
WO BOGOCEN CO24/1/ AT-5 TIME 040615 0928 PAGE 2
OPERATOR TRAFFIC RECORDING RESULTS 00

TRG MP NRP RPL RPN DATE TIME
3 8 12 30 7 040615 0900


CATY 191 199 NUM11

INCOMING CALLS
TOTINC 241 405 5
BRNO 4 15 0
ANO 234 390 5
AT1PC 98 96 60
AT2PC 100 100 100
MTA 3 3 6
OPBUSINC 0 0 0
BRWT 2 3 0

DEMAND AND DELAY CALLS
HNO 109 194 0
CANCELNO 125 184 4

DEMAND CALLS
DEMHNO 109 194 0
DEMOST 25 25 156
DEMCST 31 50 0

DELAY CALLS
DELQNO 0 0 0
DELHNO 0 0 0
DELOST 0 0 0
DELCST 0 0 0

QUEUE CALLS
QCALLSINC 39 47 3
QCONGINC 0 0 0
MQLINC 0.1 0.1 0.0
MQTIMEINC 3 5 3

QCALLSDL 0 0 0
QCONGDL 0 0 0
MQLDL 0.0 0.0 0.0
MQTIMEDL 0 0 0

QCALLSDMR 6 0 0
QCONGDMR 0 0 0
MQLDMR 0.0 0.0 0.0
MQTIMEDMR 2 0 0

QCALLSDLR 0 0 0
QCONGDLR 0 0 0
MQLDLR 0.0 0.0 0.0
MQTIMEDLR 0 0 0
END
##end second report
##first report
....TIME
09:30
###second report
......TIME
09:30


My script has a problem when it convert colums in rows for the second report, especially with the colum $4 it doesn`t print.

The script use a vector [] to convert colums in rows.


What happend I don`t know

some ideas.


Thanks again for your help

Malpa
 
- 2 missings } at end of 1st report section (after the big printf)
- missing printf "\n" after the 1st for loop
- replace print "\n" by printf "\n" to avoid blank lines
- max_nf is always=4
- you may consider if(nr1==0)nr1=NR to have a starting value for y

What is the expected result ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks for your assitance PHV

ok.You are rigth, there is a problem when i`m going to print to convert colums in rows.

The file ope.log has reports each half an hour

I expect some like this:

each half hour

040615,0900,OG,ANO,AT1PC,AT2PC,MTA,HNO,ALPVAL,AUNB
040615,0900,GCNAL,353,98,100,3,168,79,14
040615,0900,GR192,259,95,100,3,123,89,11
040615,0900,GRCOD,37,78,86,8,22,78,20

040615,0900,CATY,TOTINC,BRNO,ANO,AT1PC,AT2PC,MTA,OPBUSINC,BRWT,HNO,CANCELNO,DEMHNO,DEMOST,DEMCST,DELQNO,DELHNO,DELOST,DELCST,QCALLSINC,QCONGINC,MQLINC,MQTIMEINC,QCALLSDL,QCONGDL,MQLDL,MQTIMEDL,QCALLSDMR,QCONGDMR,MQLDMR,MQTIMEDMR,QCALLSDLR,QCONGDLR,MQLDLR,MQTIMEDLR,
040615,0900,191,241,4,234,98,100,3,0,2,109,125,109,25,31,0,0,0,0,39,0,0.1,3,0,0,0.0,0,6,0,0.0,2,0,0,0.0,0,
040615,0900,199,405,15,390,96,100,3,0,3,194,184,194,25,50,0,0,0,0,47,0,0.1,5,0,0,0.0,0,0,0,0.0,0,0,0,0.0,0,
040615,0900,NUM11,17,3,14,79,93,8,0,3,0,13,143,36,0,0,0,0,11,0,0.0,7,0,0,0.0,0,0,0,0.0,0,0,0,0.0,0


040615,0930,OG,......
040615,0930,GCNAL,...........
040615,0930,GR192,...........
040615,0930,GRCOD,...........


040615,0930,CATY...........
040615,0930,191...........
040615,0930,199.........
040615,0930,NUM11.........


Malpa

Thanks for your attendance
excuse my english


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top