Working on a script that inputs an IP, parses and outputs to another file.
A Sample of the log is as follows:
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:
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!
Try this:
awk -F, '/ip/ ; /^tagId=/{print $1 FS $3}' file
Try:
perl -ln0e '/(ip = 10\.19\.5\.6).*?(tagId=2,.*?tagId=34.*?$)/sm; print "$1\n$2"' logfile
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!
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:
awk -F, 'f && /ip/{exit} /ip/{print; f=1} /^tagId=/{print $1 FS $3}' file
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.
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 ]
Something like this?
awk -F, '/ip/{f++}f==1 && /^tagId=/{print $1 FS $3}' file
1 Like
That worked perfect! Thanks again!
nawk -F, 'f && /ip/{exit} /ip = 10.19.5.6/{print; f=1} /^tagId=/ && f{print $1 FS $3}'