Jump to content

Replace every instance of a string with another string in bash


siriusfox
 Share

Recommended Posts

Does anyone know of a way, within bash (linux), to within every file in a directory, replace every instance of a string with another. I've got a very poorly written web script that I need to do some modifications to, but the files within said directory statically rely on the name of the directory.

So within directory abc lets say, there are a bunch of PHP, config, xml, and some static HTML files. I need a script or command, that will go through all of those files and replace every instance of abc with abc_beta or something of that nature.

Any help would be great.

-Siriusfox

Link to comment
Share on other sites

find . -name '*.html' -exec sed -i 's/oldstring/newstring/g' {} ;

Note that the slashes before the accolades and the semicolon, as well as the space before the escaped semicolon are required. FYI, that bit get replaced by every matching file that find is able to find.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...