Help parsing log from vertical to horizontal line

Hi Expert,

i have log in attached (log.txt)

i want the log result become horizontal line :


recordOpeningTime,servedMSISDN,ratingGroup,datavolumeFBCUplink,datavolumeFBCDownlink
1502260153422B0800,196738930571,3,7946,2219
1502260153422B0800,196738930571,3,233,174
1502260153422B0800,196737136858,3,558,408
1502260153422B0800,196737136858,3,3901,7974
1502260153422B0800,196737136858,3,3706,1703
1502260153422B0800,196737136858,3,61,189
1502260153422B0800,196737136858,3,85855,16940
1502260153422B0800,196738639319,3,1129,3856
1502260153422B0800,196738639319,3,0,0
1502260153422B0800,196738639319,3,0,0
1502260153422B0800,196738639319,3,0,0
1502260153422B0800,196738639319,3,0,0
1502260153422B0800,196738639319,3,0,0
1502260153422B0800,196738813569,30,10682,13065
1502260153422B0800,196738813569,30,417,313
1502260153422B0800,196738813569,30,0,0
1502260153422B0800,196738813569,30,0,0
1502260153422B0800,196738813569,30,0,0
1502260153422B0800,196738813569,30,0,0
1502260153422B0800,196738813569,30,0,0

Can anybody help?

This seems similar to an earlier thread you started: Change the vertical logs to horizontal line.

Can't you use what you learned from the suggestions given there to solve this problem?

What have you tried? What is failing in what you tried?

a little bit different but still doesnt work.

awk '/recordOpeningTime \:/ {ts=$3}
     /servedMSISDN \:/ {print ts", "$3; ts="" }
     /ratingGroup \:/ {print ts", "$3; ts="" }
     /datavolumeFBCUplink \:/ {print ts", "$3; ts="" }
     /datavolumeFBCDownlink \:/ {print ts", "$3; ts="" }' 

Here is a slightly different approach that seems to work:

awk -F"'" '
BEGIN {	OFS = ","
	h[++hc] = "recordOpeningTime"
	h[++hc] = "servedMSISDN"
	h[++hc] = "ratingGroup"
	h[++hc] = "datavolumeFBCUplink"
	h[++hc] = "datavolumeFBCDownlink"
	for(i = 1; i <= hc; i++)
		printf("%s%s", h, (i == hc) ? ORS : OFS)
}
{	for(i = 1; i <= hc; i++)
		if($0 ~ h) {
			d = $2
			break
		}
	if(i == hc)
		for(i = 1; i <= hc; i++)
			printf("%s%s", d, (i == hc) ? ORS : OFS)
}' log.txt

If you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk .

In addition to the output you said should be produced from your sample log.txt file, it also prints the output:

1502260153422B0800,196738877718,3,160,958
1502260158372B0800,196738640656,30,37880,1010880
1502260158372B0800,196738640656,30,0,0
1502260158372B0800,196738640656,30,0,0
1502260158372B0800,196738640656,30,0,0
1502260158372B0800,196738640656,30,0,0

Is there some reason why these lines should have been deleted from the output?

1 Like

Thank you Don.. its should be printed but i miss it.