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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:50:25+00:00 2026-06-11T22:50:25+00:00

I found (and adapted a bit) a command to edit a list of files

  • 0

I found (and adapted a bit) a command to edit a list of files using regex (and perl). I put it into a script file called cred, so I can do cred . england England to replace all occurrences of england with England in all files in the current directory.

find $1 -type f -exec perl -e 's/'$2'/'$3'/g' -p -i {} \;

It is wicked powerful, and already useful – but dangerous, and flawed. I would like it to…

  1. preview changes (or at least files operated on) first, asking confirmation
  2. work with longer strings than a single word. I tried cred . england 'the United Kingdom' but it fails

I would also be interested in other (short and memorable, universally installed/installable on osx and ubuntu) commands to achieve the same thing.

EDIT:

This is what I have so far – open to improvements…

# highlight the spots that will be modified (not specifying the file)
find $1 -type f -exec grep -E "$2" --color {} \;
# get confirmation
read -p "Are you sure? " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
  # make changes, and highlight the spots that were changed
  find $1 -type f -exec perl -e "s/$2/$3/g" -p -i {} \;
  echo ""
  find $1 -type f -exec grep -E "$3" --color {} \;
else
  echo ""
  echo "Aborted!!"
fi
  • 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-11T22:50:27+00:00Added an answer on June 11, 2026 at 10:50 pm

    To work on strings with spaces, write your command like:

    perl -e "s/$2/$3/g"
    

    If you use double quotes, variables will be expanded inside the quotes.

    To do something like previewing changes and asking for confirmation you will need a much more complex script. One very easy thing to do would be to just run find $1 -type f first to get a listing of all the files, and then use the read command to get some input and decide if you should continue.

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

Sidebar

Related Questions

I have adapted some code from a great article I found about circle drawing
Basically my problem is that i've adapted a piece of code found here http://social.msdn.microsoft.com/Forums/en-US/vemapcontroldev/thread/62e70670-f306-4bb7-8684-549979af91c1
I'm trying to load up rails in the test environment using a ruby script.
Ok found some great code on Stack. Have adapted it slightly. But in essence
I found here a topic about an MySQL IF, ELSE query,i adapted it but
So: I have the following function, adapted from a formula found online, which takes
I found an updated version of John Gruber's regex for url matching in this
I'm using the python-openid library from Janrain at http://openidenabled.com/python-openid/ I adapted their Django example
I am using this PHP script to generate identicons. It uses Don Park's original
I found and adapted an example which scans an array for an entry like

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.