execute shell command pipeline
marklists at mceahern.com
Thu Mar 25 21:46:42 CET 2004
>I'm a Python newbie and I'm wondering how I can do the following Perl thing:
>open(F, 'grep -b 2004 logfile | head -1 | cut -d: -f1 |') or die "blah, blah";
>$offset = <F>;
>( or $offset = `grep -b 2004 logfile | head -1 | cut -d: -f1`; )
>in Python. When I tried:
You don't have to do it this verbosely, but it works:
text = '2004'
filename = 'logfile'
delim = ':'
matches = os.popen('grep -b %s %s' % (text, filename)).readlines()
first = matches
offset = first.split(delim)
# note: offset is now a string
More information about the Python-list