Shell script to parsing log


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to parsing log
# 8  
Old 12-05-2008
yep,, the output is some of query that "[trigger] 2" have

The output will be like this :

timeStamp | msisdn | contentUrl | timeDuration |
20081114082116 |6738809966|rtsp://172.28.13.66/mtvloop/MTV2GO-Loop.sdp| 5D
20081114082841 |6738621251|rtsp://172.28.13.66/mtvloop/RIA-Loop.sdp|13
....
# 9  
Old 12-05-2008
This should give you the desired output:

Code:
awk '
/\[trigger\] 02/{f=1}
/\[timeStamp\]/{ts=$4}
f && /\[msisdn\]/{msi=$4}
f && /\[contentUrl\]/{cU=$4}
f && /\[timeDuration\]/{tD=$4}
f && /APPLICATION/{
  s= ts "|" msi "|" cU "|" tD
  gsub("\047","",s)
  print s
  f=0
}' logfile

Regards
# 10  
Old 12-05-2008
yah.. success.. it works
I've learn the script and the tutorial that u give me..
but i'm still confuse about that..

can u explain the script.

thanks..
# 11  
Old 12-06-2008
Quote:
Originally Posted by justbow
yah.. success.. it works
I've learn the script and the tutorial that u give me..
but i'm still confuse about that..

can u explain the script.

thanks..
Ok, here we go:

Code:
awk '
/\[trigger\] 02/{f=1}
/\[timeStamp\]/{ts=$4}
f && /\[msisdn\]/{msi=$4}
f && /\[contentUrl\]/{cU=$4}
f && /\[timeDuration\]/{tD=$4}
f && /APPLICATION/{
  s= ts "|" msi "|" cU "|" tD
  gsub("\047","",s)
  print s
  f=0
}' logfile

Explanation:

Code:
/\[trigger\] 02/{f=1}

Set the flag f if the a line matches the pattern [trigger] 02.


Code:
/\[timeStamp\]/{ts=$4}
f && /\[msisdn\]/{msi=$4}
f && /\[contentUrl\]/{cU=$4}
f && /\[timeDuration\]/{tD=$4}

If the flag is set and the line matches the pattern, assign the 4th field to the variables msi, cU and tD.
The timestamp is on a line before the pattern "[trigger] 02", thus the variable for the timestamp ts must be filled unconditional.


Code:
f && /APPLICATION/{
  s= ts "|" msi "|" cU "|" tD
  gsub("\047","",s)

If the flag is set and the line matches the pattern "APPLICATION", use the string s to format the variables and to delete the quotes.


Code:
  print s
  f=0

Print the string s and unset the flag f.


Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

parsing using shell script

I have a file parameters.txt which contains 151524 151525 I have another file OID.csv which contains NE Version Object Type ID SDK param name Object OID test1 Start: 4.2 End: 4.2 pan 151524 speed ... (5 Replies)
Discussion started by: LavanyaP
5 Replies

2. Shell Programming and Scripting

XML parsing using shell script

I have a xml file like this <bul:collectionStrategy name="strategy1"> <bul:collectionTemplateGroup name="15min group"/> <bul:collectionTemplateGroup name="hourly group"/> </bul:collectionStrategy> <bul:CollectionTemplateGroup name="hourly group" > ... (2 Replies)
Discussion started by: LavanyaP
2 Replies

3. Shell Programming and Scripting

XML parsing in a shell script.

Below is a XML I have... <?xml version="1.0" encoding="UTF-8" ?> <component xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:XXXXX-www-Install-Manifest manifest.xsd" xmlns="urn:qqqqq-Install-Manifest" name="OM" ... (1 Reply)
Discussion started by: dashok.83
1 Replies

4. Shell Programming and Scripting

Parsing XML using Shell Script

Hello, I'm a starting shell scripter and no Perl knowledge. I've trying to do this for a while: I want to parse an XML file and get certain data out of it and write that data into a CSV file, all this using Shell Scripting (in Bash). Or Perl without any XML Parser/Interpreter (if possible). ... (1 Reply)
Discussion started by: Kage Musha
1 Replies

5. Shell Programming and Scripting

Performance of log parsing shell script very slow

Hello, I am an absolute newbie and whatever I've written in the shell script (below) has all been built with generous help from googling the net and this forum. Please forgive any schoolboy mistakes. Now to the qn, my input file looks like this - 2009:04:03 08:21:41:513,INFO... (7 Replies)
Discussion started by: sowmitr
7 Replies

6. UNIX for Dummies Questions & Answers

shell script parsing with sed

#I'm quite new to scripting and my boss has asked me to solve a simple problem and sadly, I can't figure out how to do it. Any help is appreciated. :confused: #The following is a small shell script and the output that it produces for google.com. #!/bin/sh whois $1 | grep "Name Server"... (5 Replies)
Discussion started by: jjamd64
5 Replies

7. Shell Programming and Scripting

Parsing a line in Shell Script

I have record line somthing like below with first line showing char spacing not real record line 1 | 2 | 3rd Field--------------|-4th field--| This is charcatersapcing of line DF20000000000000000130.7890000000750 I shoudl get two line from above line 1st line should 1 | 2 | 3rd... (3 Replies)
Discussion started by: unishiva
3 Replies

8. Shell Programming and Scripting

Shell script for parsing 300mb log file..

am relatively new to Shell scripting. I have written a script for parsing a big file. The logic is: Apart from lot of other useless stuffs, there are many occurances of <abc> and corresponding </abc> tags. (All of them are properly closed) My requirement is to find a particular tag (say... (3 Replies)
Discussion started by: gurpreet470
3 Replies

9. Shell Programming and Scripting

Parsing a file in Shell Script

Hi, I have a requirement. I have an application which can take a file as inputs. Now the file can contain any number of lines. The tool has to pick up the first uncommented line and begin processing it. For example the file could be like this: #MANI123|MANI1234 #MANI234|MANI247... (4 Replies)
Discussion started by: sendhilmani123
4 Replies

10. Shell Programming and Scripting

shell script argument parsing

how to parse the command line argument to look for '@' sign and the following with '.'. In my shell script one of the argument passed is email address. I want to parse this email address to look for correct format. rmjoe123@hotmail.com has '@' sign and followed by a '.' to be more... (1 Reply)
Discussion started by: rmjoe
1 Replies
Login or Register to Ask a Question