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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:00:04+00:00 2026-06-04T21:00:04+00:00

I have changed up my director structure and I want to do the following:

  • 0

I have changed up my director structure and I want to do the following:

  • Do a recursive grep to find all instances of a match
  • Change to the updated location string

One example (out of hundreds) would be:

from common.utils import debug  --> from etc.common.utils import debug

To get all the instances of what I’m looking for I’m doing:

$ grep -r 'common.' ./

However, I also need to make sure common is preceded by a space. How would I do this find and replace?

  • 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-04T21:00:06+00:00Added an answer on June 4, 2026 at 9:00 pm

    It’s hard to tell exactly what you want because your refactoring example changes the import as well as the package, but the following will change common. -> etc.common. for all files in a directory:

    sed -i 's/\bcommon\./etc.&/' $(egrep -lr '\bcommon\.' .)
    

    This assumes you have gnu sed available, which most linux systems do. Also, just to let you know, this will fail if there are too many files for sed to handle at one time. In that case, you can do this:

    egrep -lr '\bcommon\.' . | xargs sed -i 's/\bcommon\./etc.&/'
    

    Note that it might be a good idea to run the sed command as sed -i'.OLD' 's/\bcommon\./etc.&/' so that you get a backup of the original file.

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

Sidebar

Related Questions

I have a directory where I want to change all of the directory names
I want a Python object that will monitor whether other objects have changed since
I want to change the structure of the displayed client-side URL. I'm not too
Say I have this folder structure: MainFolder Folder1 Folder2 Folder3 ... Folder200 I want
I have a following directory structure in my project: bin/ dist/ include/ ├── module_a/
I want to rewrite a directory to another directory. The file/link structure to all
I would like to have a makefile copy files from another directory and change
I have changed the DefaultMode property of my details view to Insert since I
I have changed my locale to English/Great Britain (en-GB) as described here . When
I have changed a lot of things in a java code but now I

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.