Script for parsing vertical log into horizontal


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script for parsing vertical log into horizontal
# 1  
Old 11-21-2012
Script for parsing vertical log into horizontal

Hi,

I have log like this :

Quote:
QUIT q
00285_BKU_KTQEL ffff
SectorAntenna=1 30
SectorAntenna=2 30
SectorAntenna=3 0
Bye
QUIT q
02415_BKU_ERDAL ffff
SectorAntenna=1 60
SectorAntenna=2 60
SectorAntenna=3 60
Bye
QUIT q
00070_BKU_KTIZM ffff
SectorAntenna=1 60
SectorAntenna=2 60
SectorAntenna=3 60
Bye
QUIT q
00190_BKU_METBU ffff
SectorAntenna=1 90
SectorAntenna=2 100
SectorAntenna=3 80
Bye
QUIT q
00083_AGU_AGSUS ffff
Bye
QUIT q
00395_CEL_ALLAR ffff
Bye
QUIT q
00079_MAS_MASAL ffff
SectorAntenna=1 60
SectorAntenna=2 50
SectorAntenna=3 50
Bye
QUIT q
00100_BAB_BABEK ffff
Bye
QUIT q
00803_BIL_BILES ffff
Bye
And i want the output like below :
Quote:
00285_BKU_KTQEL 30 30 0
02415_BKU_ERDAL 60 60 60
00070_BKU_KTIZM 60 60 60
00190_BKU_METBU 90 100 80
00083_AGU_AGSUS
00395_CEL_ALLAR
00079_MAS_MASAL 60 50 50
00100_BAB_BABEK
00803_BIL_BILES
I have try using awk but doesn't work

Code:
awk '
/ffff /{ts=$1}
f && /SectorAntenna\=1/{sa1=$3}
f && /SectorAntenna\=2/{sa2=$3}
f && /SectorAntenna\=3/{sa3=$3}
{
  s= ts "|" sa1 "|" sa2 "|" sa3
  print s
  f=0
}'

Anybody can help me
# 2  
Old 11-21-2012
Code:
awk '!/QUIT/ { if($0=="Bye") { print "\n"; } else if ($0 ~ /SectorAntenna/) { printf "%d ", $2; } else { printf "%s ", $1; } } ' filename

# 3  
Old 11-21-2012
Hi

Code:
awk '/^[0-9]/{if (x) print x;x=$1}/Sector/{x=x FS $2}END{print x}' file

Guru.

Last edited by guruprasadpr; 11-21-2012 at 01:22 AM..
# 4  
Old 11-21-2012
How about:

Code:
awk 'NR>1{print $1,$4,$6,$8}' RS="QUIT q\n"

This User Gave Thanks to ripat For This Post:
# 5  
Old 11-21-2012
Nice solution. Smilie
Id like to explain it some.

RS="QUIT q\n" This sets the record selector to QUIT q\n instead of normal new line \n.
Since this file starts with QUIT q\n, we need to suppress the first output or it will be blank. This is done with skipping record #1 by saying that it must be greater than 1 NR>1 before printing anything.
Then print field $1,$4,$6,$8
$1 first field after QUIT q\n
$4 field after SectorAntenna=1
$6 field after SectorAntenna=2
$8 field after SectorAntenna=3
Buy is not printed since its on an odd field number and not field #1

Last edited by Jotne; 11-21-2012 at 05:33 AM.. Reason: Typo
This User Gave Thanks to Jotne For This Post:
# 6  
Old 11-21-2012
or sed
Code:
sed -n '/QUIT/d;:i;/^[0-9]/s! .*!!g;/[0-9]$/s!.* !!g;/Bye/!{H;n;bi};s!Bye.*!!g;x;s!\n! !g;s!^ !!g;p' infile

# 7  
Old 11-21-2012
Very nice and creative proposals indeed!
Anyhow, the requestor's solution can be slightly adapted/pruned and will work also (pls note that he seems to want a pipe symbol separator):
Code:
awk '/ffff/ {ts=$1}
     /SectorAntenna/ {ts=ts"|"$2}
     /Bye/ {print ts; ts="" }
    ' file
00285_BKU_KTQEL|30|30|0
02415_BKU_ERDAL|60|60|60
00070_BKU_KTIZM|60|60|60
00190_BKU_METBU|90|100|80
00083_AGU_AGSUS
00395_CEL_ALLAR
00079_MAS_MASAL|60|50|50
00100_BAB_BABEK
00803_BIL_BILES

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Print vertical to horizontal

Hi Masters, I need help to change my vertical data to horisontal input 2015-04-13|JS|741667 2015-04-13|JSJ|2272 2015-04-13|TMS|107099 2015-04-12|JMD|47945 2015-04-13|TM|760024 2015-04-13|JM|484508 2015-04-14|JMJ|318 2015-04-14|JSD|54436 2015-04-13|JM|15410 Output... (2 Replies)
Discussion started by: radius
2 Replies

2. Emergency UNIX and Linux Support

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... (4 Replies)
Discussion started by: justbow
4 Replies

3. UNIX for Dummies Questions & Answers

Change Vertical to Horizontal

I need to change data from vertical to horizontal but with condition input USA|80 AUS|40 BRA|33 VEGAS|40 KENTUCKY|50 NEWYORK|21 DARWIN|33 ADELAIDE|21 SAOPAOLO|44 RIO|89 GAPIZA|44 BENFLEX|32 AXIS|44 ACRE|56 HEIGHT|22 (5 Replies)
Discussion started by: radius
5 Replies

4. Shell Programming and Scripting

Script awk vertical to horizontal with some condition

hi all.. i have problem, right now i want to processing some data with input like this BIMAB ACF-0168 QTS-0465 QUA 2013-08-17 14:16:09.34 ** ALAR ORX -004 NDORIDUNGGA (21943) 7745 ABOVE DEFINED 02 00 01 00 00 00 01 00 00 01 03... (12 Replies)
Discussion started by: buncit8
12 Replies

5. Shell Programming and Scripting

How do i do the vertical to horizontal??

51009 8746 8912 17986 20315 24998 5368 38934 7805 8566 (4 Replies)
Discussion started by: nikhil jain
4 Replies

6. Shell Programming and Scripting

Need perl or shell script to sort vertical lines to horizontal line in csv format

Need perl or shell script to sort vertical lines to horizontal line in csv format My file like below ------------------------- ================================================================================ PATH PINKY1000#I1-1-ZENTA1000-2#I7-1-ASON-SBR-UP-943113845 ... (4 Replies)
Discussion started by: sreedhargouda.h
4 Replies

7. Shell Programming and Scripting

Vertical And Horizontal Pivoting

Hi All, My Input data is: A=1 B=2 My desired Output should be: A|B 1|2 Thanks in advance... (3 Replies)
Discussion started by: kmsekhar
3 Replies

8. Shell Programming and Scripting

change log vertical to horizontal lines

Hi, Need help unix command to change this : become this Anyone can help me?:wall: (2 Replies)
Discussion started by: justbow
2 Replies

9. UNIX for Dummies Questions & Answers

vertical to horizontal

dear all, i'm new to unix and i try to figure out the best case for making list of vertical text to become horizontal and skip the line 1 and 2. example text : Data DATE XXXXX MAX 47 53 49 51 48 48 7 46 51 8 25 (6 Replies)
Discussion started by: andrisetia
6 Replies

10. UNIX for Dummies Questions & Answers

Horizontal to vertical

Hi, Silly question, if I have an excel file that looks something like this: ................. Subject 1 Subject 2 Subject 3 Subject 4 Fever..............13...........9.............23..........14 Headache.........2............12...........18..........23... (3 Replies)
Discussion started by: Xterra
3 Replies
Login or Register to Ask a Question