Emergency UNIX and Linux Support

Please post your urgent questions here for highest visibility. Posting a new thread to this forum requires Bits. We monitor this forum to help people with emergencies, but we do not guarantee response time or answers. This forum is "best effort" only. Members who reply to posts here receive a bonus of 1000 Bits per reply.

Help parsing log from vertical to horizontal line

👤 Login to reply

 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-26-2015
justbow justbow is offline
Registered User
 
Join Date: Dec 2008
Last Activity: 6 March 2018, 1:41 AM EST
Posts: 90
Thanks: 15
Thanked 1 Time in 1 Post
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 :

Code:
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?
Sponsored Links
    #2  
Old 02-26-2015
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 21 July 2018, 4:00 AM EDT
Location: San Jose, CA, USA
Posts: 11,411
Thanks: 651
Thanked 3,971 Times in 3,394 Posts
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?
Sponsored Links
    #3  
Old 02-27-2015
justbow justbow is offline
Registered User
 
Join Date: Dec 2008
Last Activity: 6 March 2018, 1:41 AM EST
Posts: 90
Thanks: 15
Thanked 1 Time in 1 Post
a little bit different but still doesnt work.

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

    #4  
Old 02-27-2015
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 21 July 2018, 4:00 AM EDT
Location: San Jose, CA, USA
Posts: 11,411
Thanks: 651
Thanked 3,971 Times in 3,394 Posts
Here is a slightly different approach that seems to work:
Code:
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], (i == hc) ? ORS : OFS)
}
{	for(i = 1; i <= hc; i++)
		if($0 ~ h[i]) {
			d[i] = $2
			break
		}
	if(i == hc)
		for(i = 1; i <= hc; i++)
			printf("%s%s", d[i], (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:
Code:
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?
The Following User Says Thank You to Don Cragun For This Useful Post:
justbow (02-28-2015)
Sponsored Links
    #5  
Old 02-28-2015
justbow justbow is offline
Registered User
 
Join Date: Dec 2008
Last Activity: 6 March 2018, 1:41 AM EST
Posts: 90
Thanks: 15
Thanked 1 Time in 1 Post
Quote:
Originally Posted by Don Cragun View Post
Is there some reason why these lines should have been deleted from the output?
Thank you Don.. its should be printed but i miss it.
Sponsored Links
👤 Login to reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Change the vertical logs to horizontal line justbow Shell Programming and Scripting 1 12-12-2013 02:07 AM
Script for parsing vertical log into horizontal justbow Shell Programming and Scripting 7 11-21-2012 09:23 PM
change log vertical to horizontal lines justbow Shell Programming and Scripting 2 01-27-2012 04:27 PM
How to move vertical line to Horizontal... Arsh10 UNIX for Dummies Questions & Answers 3 11-15-2011 10:56 AM
Draw a Horizontal and Vertical line on UNIX allways4u21 Shell Programming and Scripting 11 02-09-2009 04:28 PM



All times are GMT -4. The time now is 05:30 AM.

Unix & Linux Forums Content Copyright1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?