In this regard, Python is not as convenient as Perl, but you can get closer to the Perl -p icon using fileinput , for example:
python -c 'for ln in __import__("fileinput").input(): print ln.rstrip()' files...
This will automatically open files in a sequence similar to Perl, or use standard input if files are not provided. Replace print with any kind of processing. You may need a few lines to do something useful, but this is not a problem for most shells.
Note that rstrip necessary to avoid duplicating newlines from the original lines and those added by the print statement. If you are not printing a line, you do not need to call it.
source share