I had a directory "/pcap_test" which contains several log files. Each file has a pattern like:
Pkt: 1 (358 bytes), LIFE: 1, App: itunes (INTO), State: TERMINATED, Stack: /ETH/IP/UDP/itunes, Error: None
Pkt: 2 (69 bytes), LIFE: 2, App: zynga (INTO), State: INSPECTING, Stack: /ETH/IP/UDP, Error: None
Pkt: 3 (149 bytes), LIFE: 2, App: pizzeria (INTO), State: TERMINATED, Stack: /ETH/IP/UDP/pizzeria, Error: None
In this case I want the output to be the second line because the content in the "App" is not present in the "Stack: "
I wrote a small Python script to iterate through the directory, open each file and print the output:
import os
list = os.listdir("/home/test/Downloads/pcap_test")
print list
for infile in list:
infile = os.path.join("/home/test/Downloads/pcap_test" , infile)
if os.path.isfile(infile):
str = file(infile, 'r').read()
print str
I somehow got the output using grep but unable to use the same in the python script. Its something like:
grep -vP 'App: ([^, ]*) \(INTO\).*Stack: .*\1.*$' xyz.pcap.log | grep -P 'App: ([^, ]*) \(INTO\)'
Since I already have the file named "str" , I want to use that rather than individual log files, to get the output.
Any help in this regard will be highly appreciated.