[Tutor] Processing Linux command line output
Gareth Allen
gallen at openworld.co.za
Thu Apr 25 00:03:50 CEST 2013
Hi all,
I'm trying to get the output of a command and split it into a list that I
can process. What is the best way to go about doing this? In bash I would
use tools like grep, sed awk etc.
Here's an example:
ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:84253 errors:0 dropped:0 overruns:0 frame:0
TX packets:84253 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:11763964 (11.2 MiB) TX bytes:11763964 (11.2 MiB)
I would like to end up with something like this in a file:
<unix timestamp>,lo,rx_errors=0,rx_dropped=0,rx_overruns=0,rx_frame=0
Thanks,
Gareth
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130425/d177426a/attachment.html>
More information about the Tutor
mailing list