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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:43:36+00:00 2026-05-27T15:43:36+00:00

Every time this situation pops up, which is about once every few months, I

  • 0

Every time this situation pops up, which is about once every few months, I end up spending way too long trying to figure out a bash script that does exactly what I want. I am pretty sure what I want is similar to what everyone else wants, but more often than not the available scripts online when I do a quick search are oversimplified and don’t do these things (and my own bash scripting skills aren’t good enough to figure it out):

  1. It needs to be recursive (traverse an entire folder tree)
  2. It must allow me to choose the type of file (e.g. “*.js”) because sometimes the folder tree contains binaries and other file types that shouldn’t be searched
  3. It should replace the text in-place, editing the existing files
  4. It shouldn’t cause source control (git, svn) to think the file has been modified unless it actually has been modified (I don’t know why but sed seems to do this)
  5. It should allow for regular expressions

What is the SIMPLEST way to accomplish this? I mean, I could write a script in python, it would only be a few lines, but I feel like this should be easy to accomplish in the shell.

  • 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-05-27T15:43:37+00:00Added an answer on May 27, 2026 at 3:43 pm

    I typically do something like this:

    find . -name '*.hpp' -o -name '*.cpp' | xargs grep -l StuffToEdit
    

    I then see if I’m getting the files of interest. If I am, I add to the pipeline:

    | xargs sed -i 's@StuffToEdit@NewStuffInstead@g'
    

    And let ‘er rip.

    If sed is making your VCS think files are changed when they aren’t, you should look at the diffs. Perhaps you have whitespace turned off in your diffs but that’s what’s changing (line endings or the like)?

    I’m sure someone will come and point out that one or both of my uses of xargs up there are not necessary, but for one-off jobs, it doesn’t matter. I prefer these multi-program pipelines for this sort of task anyway, since I can easily disable or swap out certain filters and check the results of the rest if the results are not correct at first.

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

Sidebar

Related Questions

how would I increment the key [i] by 1 in this situation every time
Every time I call this method my NSMutableData is leaking and I cannot figure
Every time in PHP when I make a variable such as this one: $date
I have this warning every time I run my CGI-script (output is rendered by
I seem to make this mistake every time I set up a new development
I tried decoding this base64 string so many times but every time i get
I find this syntax astoundingly annoying. Every time I rename my class, I have
I think beestings change the html every time. this means html is not able
I'm sure this is a newbie question, but every time I've compiled/dl'ed a new
This seems like it should be something very easy to do, but every time

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.