Help parsing log from vertical to horizontal line

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 02-26-2015
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?
# 2  
Old 02-27-2015
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?
# 3  
Old 02-27-2015
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
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?
This User Gave Thanks to Don Cragun For This Post:
justbow (02-28-2015)
# 5  
Old 02-28-2015
Quote:
Originally Posted by Don Cragun
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.
Login to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Similar Threads More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need to move vertical to horizontal using paste ranjancom2000 Shell Programming and Scripting 9 02-17-2018 08:28 PM
Print vertical to horizontal radius UNIX for Dummies Questions & Answers 2 04-15-2015 06:30 AM
Change Vertical to Horizontal radius UNIX for Dummies Questions & Answers 5 02-06-2015 07:36 AM
Change the vertical logs to horizontal line justbow Shell Programming and Scripting 1 12-12-2013 03:07 AM
How do i do the vertical to horizontal?? nikhil jain Shell Programming and Scripting 4 03-01-2013 10:02 AM
Script for parsing vertical log into horizontal justbow Shell Programming and Scripting 7 11-21-2012 10:23 PM
Need perl or shell script to sort vertical lines to horizontal line in csv format sreedhargouda.h Shell Programming and Scripting 4 09-09-2012 03:08 AM
Vertical And Horizontal Pivoting kmsekhar Shell Programming and Scripting 3 02-01-2012 07:32 AM
change log vertical to horizontal lines justbow Shell Programming and Scripting 2 01-27-2012 05:27 PM
How to move vertical line to Horizontal... Arsh10 UNIX for Dummies Questions & Answers 3 11-15-2011 11:56 AM
vertical to horizontal andrisetia UNIX for Dummies Questions & Answers 6 10-03-2011 07:03 AM
Horizontal to vertical Xterra UNIX for Dummies Questions & Answers 3 09-09-2011 12:54 PM
Need help in changing vertical lines to horizontal line in a file rocky1954 Shell Programming and Scripting 2 03-04-2011 07:54 PM
Draw a Horizontal and Vertical line on UNIX allways4u21 Shell Programming and Scripting 11 02-09-2009 05:28 PM
converting horizontal line to vertical line vasikaran UNIX for Dummies Questions & Answers 3 07-01-2005 02:10 AM
All times are GMT -4. The time now is 10:19 PM.

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





Not a Forum Member?
Forgot Password?