convert script awk in python

pjfarley3 at earthlink.net pjfarley3 at earthlink.net
Sat Mar 27 14:14:06 EDT 2021


Many thanks for the link to that document.  Most helpful.

Peter

> -----Original Message-----
> From: Michael Torrie <torriem at gmail.com>
> Sent: Friday, March 26, 2021 8:32 PM
> To: python-list at python.org
> Subject: Re: convert script awk in python
> 
> On 3/25/21 1:14 AM, Loris Bennett wrote:
> > Does any one have a better approach?
> 
> Not as such.  Running a command and parsing its output is a relatively
> common task. Years ago I wrote my own simple python wrapper function
> that would make it easier to run a program with arguments, and capture
> its output.  I ended up using that wrapper many times, which saved a lot
> of time.
> 
> When it comes to converting a bash pipeline process to Python, it's
> worth considering that most of pipelines seem to involve parsing using
> sed or awk (as yours do), which is way easier to do from python without
> that kind of pipelining. However there is a fantastic article I read
> years ago about how generators are python's equivalent to a pipe.
> Anyone wanting to replace a bash script with python should read this:
> 
> https://www.dabeaz.com/generators/Generators.pdf
> 
> Also there's an interesting shell scripting language based on Python
> called xonsh which makes it much easier to interact with processes like
> bash does, but still leveraging Python to process the output.
> https://xon.sh/ .
--



More information about the Python-list mailing list