i want pipe output of ps -ef
python line line.
the script using (first.py) -
#! /usr/bin/python import sys line in sys.argv: print line
unfortunately, "line" split words separated whitespace. so, example, if
echo "days go , still" | xargs first.py
the output
./first.py days go , still
how write script such output
./first.py days go , still
?
i not quite understand why want use commandline arguments instead of reading standard input. python has simple idiom iterating on lines @ stdin:
import sys line in sys.stdin: sys.stdout.write(line)
my usage example:
$ echo -e "first line\nsecond line" | python python_iterate_stdin.py first line second line
your usage example:
$ echo "days go , still" | python python_iterate_stdin.py days go , still
Comments
Post a Comment