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:

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:

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!

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.

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}'

:wink: