Tell me more ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
3  
This belongs on stack overflow, not here. – goldilocks Feb 19 at 7:32

closed as off topic by goldilocks, rahmu, manatwork, warl0ck, Renan Feb 19 at 12:48

Questions on Unix & Linux Stack Exchange are expected to relate to Unix or Linux within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.

If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

Try this

import commands
a=commands.getoutput('grep -vP 'App: ([^, ]*) \(INTO\).*Stack: .*\1.*$' $str | grep -P 'App: ([^, ]*) \(INTO\)')'
share|improve this answer
   
This has no chance of working as long as the quotes are wrong... – dancek Feb 19 at 8:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.