How to read from STDIN in python from a piped grep output [duplicate]

This question already has an answer here:

Let’s say I have a text file and grep "@" file.txt returns:

(1) preparing corpus @ Tue Apr 28 20:19:31 CEST 2015
(1.0) selecting factors @ Tue Apr 28 20:19:31 CEST 2015
(1.2) creating vcb file /media/2tb/ccexp/phrase-mkcls-mgiza-10clusters/work.en-ru/training/corpus/en.vcb @ Tue Apr 28 20:19:31 CEST 2015

And I want to use my python script that reads that output using something like:

grep "@" file.txt | python process.py

I’ve tried this (process.py but it only reads the first line:

import sys
logfile = raw_input()
print raw_input()

[out]:

(1) preparing corpus @ Tue Apr 28 20:19:31 CEST 2015

How do I read all the lines piped into the python script?


Source: bash

Leave a Reply