Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8476889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:18:12+00:00 2026-06-10T18:18:12+00:00

Possible Duplicate: Python equivalent to perl -pe? Is there a way to process each

  • 0

Possible Duplicate:
Python equivalent to perl -pe?

Is there a way to process each line of stdin with a given Python command without setting up things with boilerplate code?

With Perl, I can just do something like:

perl -pe '... command ...'

can I do the same with Python?

Note: something similar is possible with many other tools, e.g. sed, awk, etc…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:18:14+00:00Added an answer on June 10, 2026 at 6:18 pm

    Python is not as convenient as Perl in this regard, but you can get close to Perl’s -p flag using fileinput, like this:

    python -c 'for ln in __import__("fileinput").input(): print ln.rstrip()' files...
    

    This will automatically open files in sequence like Perl does, or use the standard input if no files are provided. Replace print with any kind of processing. You might need multiple lines to do anything useful, but that is not a problem for most shells.

    Note that rstrip is needed to avoid duplication of newlines from the source lines and those added by the print statement. If you’re not printing the line, you don’t need to call it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What's the best way to grab/parse command line arguments passed to a
Possible Duplicate: Does JavaScript have a range() equivalent? Is there a way to declare
Possible Duplicate: Python: What is the best way to check if a list is
Possible Duplicate: python: how to jump to a particular line in a huge text
Possible Duplicate: Python program to find fibonacci series. More Pythonic way. Hey, i was
Possible Duplicate: Static class variables in Python What is the Python equivalent of static
Possible Duplicate: How to convert decimal to hex in JavaScript? Is there an equivalent
Possible Duplicate: Assignment Condition in Python While Loop What's the equivalent of this: while
Possible Duplicate: Python: How to read huge text file into memory To process a
Possible Duplicate: Python Ternary Operator Does Python have an equivalent of the ternary operator?:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.