Grep Equivalent for Python

Alex Martelli aleax at mac.com
Thu Mar 15 06:47:44 CET 2007


tereglow <tom.rectenwald at eglow.net> wrote:
   ...
> server using the /proc FS.  For example, in order to obtain the amount
> of physical memory on the server, I would do the following in shell:
> 
> 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 "pipe grep into 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!-).


Alex



More information about the Python-list mailing list