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 7896569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:55:41+00:00 2026-06-03T07:55:41+00:00

A bug in some code I wrote resulted in some files being formatted incorrectly.

  • 0

A bug in some code I wrote resulted in some files being formatted incorrectly. If it were only one file, I could write

cat filename | sed 's/bad/good/g' >filename2
mv filename2 filename

and fix it. I have several hundred files, however, and I would like to make the same transformation on all of them.

Is there some way to apply the same transformation to a large number of files with sed, keeping the filenames the same?

Is sed even the right tool for this job? If not, what should I use?

  • 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-03T07:55:42+00:00Added an answer on June 3, 2026 at 7:55 am

    Use the -i (in-place) option on modern versions of sed.

    sed -i 's/bad/good/g' file*pattern
    

    or, with find

    find . -type f -name 'file*pattern' -print0 | xargs -0 sed -i 's/bad/good/g'
    

    If you’re concerned about something going awry, you can supply a suffix as an argument to -i, and a backup copy of each file will be saved with that suffix before the transformation is applied:

    sed -i.bak 's/bad/good/g' filename
    diff filename.bak filename
    

    If your version of sed doesn’t support the -i option, you can always use perl, which is where sed got the idea (only fair, since much of perl’s command-line syntax comes from sed):

    perl -pi.bak -e 's/bad/good/g' filenames
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i encountered a bug in some c code i wrote, and while it was
trying to fix a CSS bug for some code that someone else wrote. I'm
I just found a bug in some code I didn't write and I'm a
I have a very strange bug, which I believe is caused by some code
We wrote some code involving usort which works fine on our development systems (PHP
I'm trying to use some code that I wrote on another computer that splits
My code write a XML file with the LSSerializer class : DOMImplementation impl =
I'm having a problem with __sync_fetch_and_and incorrectly performing. I wrote the following code to
So, I have a local .rdlc file with some text formatted using strikethrough formatting.
I am trying to write some code that allows SVG elements to be dragged

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.