Grep Equivalent for Python

tereglow tom.rectenwald at eglow.net
Mon Mar 19 11:33:47 EDT 2007


On Mar 18, 7:33 pm, a... at pythoncraft.com (Aahz) wrote:
> In article <1174255846.721961.108... at e1g2000hsg.googlegroups.com>,
>
>
>
>
>
> tereglow <tom.rectenw... at eglow.net> wrote:
> >On Mar 15, 1:47 am, a... at mac.com (Alex Martelli) wrote:
> >> tereglow <tom.rectenw... at eglow.net> wrote:
>
> >>>grep^MemTotal /proc/meminfo | awk '{print $2}'
>
> >> If you would indeed do that, maybe it's also worth learning something
> >> more about the capabilities of your "existing" tools, since
>
> >>   awk '/^MemTotal/ {print $2}' /proc/meminfo
>
> >> is a more compact and faster way to perform exactly the same task.
>
> >> (You already received a ton of good responses about doing this in
> >> Python, but the "pipegrepinto awk instead of USING awk properly in the
> >> first place!" issue has been a pet peeve of mine for almost 30 years
> >> now, and you know what they say about old dogs + new tricks!-).
>
> >I had no idea you could do that.  Thanks for the tip, I need to start
> >reading that awk/sed book collecting dust on my shelf!
>
> Your other option is to completely abandon awk/sed.  I started writing
> stuff like this in Turbo Pascal back in the early 80s because there
> simply wasn't anything like awk/sed available for CP/M.  In the 90s, when
> I needed to do similar things, I used Perl.  Now I use Python.
>
> From my POV, there is really no reason to learn the advanced shell
> utilities.
> --
> Aahz (a... at pythoncraft.com)           <*>        http://www.pythoncraft.com/
>
> "Typing is cheap.  Thinking is expensive."  --Roy Smith- Hide quoted text -
>
> - Show quoted text -

Well, my goal is to become proficient enough at Python, that I can
replace most shell functionality with it.  I was partially successful
when learning Perl.  The trouble is that I started with shell, awk/sed/
grep, that sort of stuff.  It is somewhat difficult to break free of
"shell" like thinking and programming when you have created habits of
coding in that style.  I've recently started to work with an
application (HP Application Mapping) that has an awful lot of Jython
code running in the background; so that project sort of inspired me to
start really digging into Python; to gain a better understanding of
the application, and for any added benefit; especially in regards to
automating systems administration.  Am really enjoying learning it,
though it hurts the head a bit, trying to re-train myself.  Things
take time though, I'm not giving up!




More information about the Python-list mailing list