Convert AWK regex to Python

Chris Angelico rosuav at gmail.com
Mon May 16 04:31:03 EDT 2011


On Mon, May 16, 2011 at 6:19 PM, J <jnr.gonzalez at googlemail.com> wrote:
> cat logs/pdu_log_fe.log | awk -F\- '{print $1,$NF}' | awk -F\. '{print $1,$NF}' | awk '{print $1,$4,$5}' | sort | uniq | while read service command status; do echo "Service: $service, Command: $command, Status: $status, Occurrences: `grep $service logs/pdu_log_fe.log | grep $command | grep $status | wc -l | awk '{ print $1 }'`" >> logs/pdu_log_fe_clean.log; done

Small side point: Instead of "| sort | uniq |", you could use a Python
dictionary. That'll likely speed things up somewhat!

Chris Angelico



More information about the Python-list mailing list