using python on the command line with 'here-documents' and pipes

calmar calmar at calmar.ws
Sun Nov 14 19:40:39 CET 2004


On 2004-11-14, Jeremy Bowers <jerf at jerf.org> wrote:


hi,

> Can you post a working example for awk? I'll admit I'm not a shell
> expert,
> but it seems like you are trying to stuff two files onto stdin, the
> "echo"
> result and the python program. I don't understand how that could ever
> work, and now you've piqued my curiosity.
>

Well, it would be something like (easy example):

echo -e 'line1\nline2\nline3' | python -c '
import sys
for line in sys.stdin:
        print line'

That works now (with bash). I get the text into python and can do there
whatever I want. Awk/Sed/grep or whatever kind of tasks.

My problem, I didn't find the solution to just write the code after the
-c '...' including newlines. Sooo easy, but I didn't find that solution
(not even after hours doing curious stuff:)

Cheers
calmar

PS: would there be a smarter way to get the
stdin lines into a loop?

-- 
  calmar
          (o_  It rocks: LINUX + Command-Line-Interface
          //\
          V_/_                     http://www.calmar.ws



More information about the Python-list mailing list