Script for Parsing Log File


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script for Parsing Log File
# 1  
Old 03-23-2011
Script for Parsing Log File

Working on a script that inputs an IP, parses and outputs to another file.

A Sample of the log is as follows:
Quote:
ip = 10.19.5.6
reboot time = 1300822564
hardware type = random
registration time = 1300823600
hubId = 1
tagId=2, length=6, value=[ 20 20 10 72 34 11 ]
tagId=3, length=4, value=[ 18 16 10 10 ]
tagId=1, length=2, value=[ 00 1c ]
tagId=16, length=2, value=[ 00 00 ]
tagId=32, length=1, value=[ 00 ]
tagId=33, length=1, value=[ 00 ]
tagId=34, length=1, value=[ 00 ]
tagId=35, length=0, value=[ ]
tagId=35, length=0, value=[ ]
tagId=35, length=0, value=[ ]
tagId=35, length=0, value=[ ]
tagId=35, length=0, value=[ ]
tagId=35, length=0, value=[ ]
tagId=35, length=0, value=[ ]
tagId=35, length=0, value=[ ]
tagId=35, length=0, value=[ ]
tagId=35, length=0, value=[ ]
tagId=48, length=4, value=[ 00 00 00 01 ]
tagId=64, length=4, value=[ 00 00 00 11]
tagId=65, length=1, value=[ 00 ]
tagId=80, length=2, value=[ 00 00 ]
tagId=81, length=2, value=[ 00 00 ]
tagId=144, length=2, value=[ 00 00 ]
tagId=4, length=1, value=[ 00 ]
tagId=128, length=9, value=[ 11 1e 16 1e 18 1e 26 20 23 ]
tagId=129, length=18, value=[ 10 2b 15 29 11 1e 25 1e 22 1f 26 1e 20 1e 12 18
10 11 ]
I need the script to be able to input IP and print the data in an output file in the following format or something similar:

Quote:
IP = 10.19.5.6
tagId=2, value=[ 20 20 10 72 34 11 ]
tagId=3, value=[ 18 16 10 10 ]
tagId=1, value=[ 00 1c ]
tagId=16, value=[ 00 00 ]
tagId=32, value=[ 00 ]
tagId=33, value=[ 00 ]
tagId=34, value=[ 00 ]
and so on
Thanks for any help you can give me!
# 2  
Old 03-23-2011
Try this:
Code:
awk -F, '/ip/ ; /^tagId=/{print $1 FS $3}' file

# 3  
Old 03-23-2011
Try:
Code:
perl -ln0e '/(ip = 10\.19\.5\.6).*?(tagId=2,.*?tagId=34.*?$)/sm; print "$1\n$2"' logfile

# 4  
Old 03-23-2011
Quote:
Originally Posted by Franklin52
Try this:
Code:
awk -F, '/ip/ ; /^tagId=/{print $1 FS $3}' file


This is good but it needs to stop printing once it hits the next IP=

That way im only pullling values for that particular IP rather than all the tagids in the whole log

Thanks so much for your replies!
# 5  
Old 03-23-2011
Quote:
Originally Posted by Winsarc
This is good but it needs to stop printing once it hits the next IP=

That way im only pullling values for that particular IP rather than all the tagids in the whole log

Thanks so much for your replies!
Try:
Code:
awk -F, 'f && /ip/{exit} /ip/{print; f=1} /^tagId=/{print $1 FS $3}' file

# 6  
Old 03-24-2011
That got it to stop after it pulled the info after the correct IP, but I am still getting data above it from previous fields. See below. I need to cut out all the data above the IP address.

Quote:
tagId=2, value=[ 20 20 10 72 34 11 ]
tagId=3, value=[ 18 16 10 10 ]
tagId=1, value=[ 00 1c ]
tagId=16, value=[ 00 00 ]
tagId=32, value=[ 00 ]
tagId=33, value=[ 00 ]
tagId=34, value=[ 00 ]
tagId=35, value=[ ]
tagId=35, value=[ ]
tagId=35, value=[ ]
tagId=35, value=[ ]
tagId=35, value=[ ]
tagId=35, value=[ ]
tagId=35, value=[ ]
tagId=35, value=[ ]
tagId=35, value=[ ]
tagId=35, value=[ ]
tagId=48, value=[ 00 00 00 01 ]
tagId=64, value=[ 00 00 00 11]
tagId=65, value=[ 00 ]
tagId=80, value=[ 00 00 ]
tagId=81, value=[ 00 00 ]
tagId=144, value=[ 00 00 ]
tagId=4, value=[ 00 ]
tagId=128, value=[ 11 1e 16 1e 18 1e 26 20 23 ]
tagId=129, value=[ 10 2b 15 29 11 1e 25 1e 22 1f 26 1e 20 1e 12 18
10 11 ]
ip = 10.19.5.6
tagId=2, value=[ 20 20 10 72 34 11 ]
tagId=3, value=[ 18 16 10 10 ]
tagId=1, value=[ 00 1c ]
tagId=16, value=[ 00 00 ]
tagId=32, value=[ 00 ]
tagId=33, value=[ 00 ]
tagId=34, value=[ 00 ]
tagId=35, value=[ ]
tagId=35, value=[ ]
tagId=35, value=[ ]
tagId=35, value=[ ]
tagId=35, value=[ ]
tagId=35, value=[ ]
tagId=35, value=[ ]
tagId=35, value=[ ]
tagId=35, value=[ ]
tagId=35, value=[ ]
tagId=48, value=[ 00 00 00 01 ]
tagId=64, value=[ 00 00 00 11]
tagId=65, value=[ 00 ]
tagId=80, value=[ 00 00 ]
tagId=81, value=[ 00 00 ]
tagId=144, value=[ 00 00 ]
tagId=4, value=[ 00 ]
tagId=128, value=[ 11 1e 16 1e 18 1e 26 20 23 ]
tagId=129, value=[ 10 2b 15 29 11 1e 25 1e 22 1f 26 1e 20 1e 12 18
10 11 ]
# 7  
Old 03-24-2011
Something like this?
Code:
awk -F, '/ip/{f++}f==1 && /^tagId=/{print $1 FS $3}' file

This User Gave Thanks to Franklin52 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing a log file and creating a report script

The log file is huge and lot of information, i would like to parse and make a report . below is the log file looks like: REPORT DATE: Mon Aug 10 04:16:17 CDT 2017 SYSTEN VER: v1.3.0.9 TERMINAL TYPE: prod SYSTEM: nb11cu51 UPTIME: 04:16AM up 182 days 57 mins min MODEL, TYPE, and SN:... (8 Replies)
Discussion started by: amir07
8 Replies

2. Shell Programming and Scripting

Issue with awk script parsing log file

Hello All, I am trying to parse a log file and i got this code from one of the good forum colleagues, However i realised later there is a problem with this awk script, being naive to awk world wanted to see if you guys can help me out. AWK script: awk '$1 ~ "^WRITER_" {p=1;next}... (18 Replies)
Discussion started by: Ariean
18 Replies

3. Shell Programming and Scripting

Parsing Log File help

Hi, I am a newbie to scripting. I have multiple log files (saved as .gz) in a directory that looks like this 01-01-2013 10:00 pn: 123 01-01-2013 10:00 sn: 987 01-01-2013 10:00 Test1 01-01-2013 10:00 Result: Pass 01-01-2013 10:00 Time: 5:00 01-01-2013 10:00 Test2 01-01-2013 10:00... (3 Replies)
Discussion started by: linuxnew
3 Replies

4. Shell Programming and Scripting

Script for parsing vertical log into horizontal

Hi, I have log like this : And i want the output like below : I have try using awk but doesn't work 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 }' (7 Replies)
Discussion started by: justbow
7 Replies

5. Shell Programming and Scripting

Log parsing script

Hello, I have a script that parses logs and sends the output via digitally signed and encrypted email. This script uses grep -v to exclude patterns in a file. The problem I have is if this is run via cron none of the pattern matching seems to occur. If I run it by hand it runs exactly as it is... (2 Replies)
Discussion started by: wpfontenot
2 Replies

6. Shell Programming and Scripting

Shell script to parsing log

Hi I Have log like this : 0 234: { 3 2: 04 EE 7 14: '20081114081' 23 1: 00 79 10: '38809' 91 15: '528111510010159' 143 29: 'Streaming/downloading service' 174 3: 'MTV' 179 43: 'rtsp://172.28/MTV2GO-Loop.sdp' 224 1: 05 ... (10 Replies)
Discussion started by: justbow
10 Replies

7. UNIX for Dummies Questions & Answers

Script for parsing details in a log file to a seperate file

Hi Experts, Im a new bee for scripting, I would ned to do the following via linux shell scripting, I have an application which throws a log file, on each action of a particular work with the application, as sson as the action is done, the log file would vanish or stops updating there, the... (2 Replies)
Discussion started by: pingnagan
2 Replies

8. Shell Programming and Scripting

mail log parsing script in need of makeover

Dear unix forum members, I'm working on a script that will parse a mail machine's logs and print a list of email addresses in this format: sender@domain,recipient@domain The logs look something like this: 06:50:04 0048317AC863: client=localhost.com 06:50:04 0048317AC863:... (7 Replies)
Discussion started by: jjamd64
7 Replies

9. Shell Programming and Scripting

Help with script parsing a log file

I have a large log file, which I want to first use grep to get the specific lines then send it to awk to print out the specific column and if the result is zero, don't do anything. What I have so far is: LOGDIR=/usr/local/oracle/Transcription/log ERRDIR=/home/edixftp/errors #I want to be... (3 Replies)
Discussion started by: mevasquez
3 Replies

10. 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
Login or Register to Ask a Question