Here I use sed to replace every occurrence of the word "cybernetnews" with "cybernet" in every file with the extension, c, in the directory, /home/user/directory/.
find /home/user/directory -name \*.c -exec sed -i "s/cybernetnews/cybernet/g" {} \;
A more generic variation where you search recursively from the directory of execution and operate on only regular, readable, writeable files:
find ./ -type f -readable -writable -exec sed -i "s/cybernetnews/cybernet/g" {} \;
The stream editor,sed, is a powerful utility for this kind of work and is my first choice, however, if you want to do this from an ordinary text editor using an Ubuntu based native application, I would suggest you take a look at Jedit, It is available in the repositories and can be installed by typing in your console:
sudo apt-get install jedit
Start jedit, click the search menu item, in the menu list, click the Search in Directory item, you will be presented with the dialog below:
This is similar to that of Notepad++ and does the same thing, I believe this is what you want.
replaces any occurence of oldtext by newtext in all files in the current folder. However you will have to escape all perl special characters within oldtext and newtext using the backslash.
You can use this script, copy code and make a file find_and_replace_in_files.sh.
I have modified it a little; please tell me your opinion.
# *****************************************************************************************
# find_and_replace_in_files.sh
# This script does a recursive, case sensitive directory search and replace of files
# To make a case insensitive search replace, use the -i switch in the grep call
# uses a startdirectory parameter so that you can run it outside of specified directory - else this script will modify itself!
# *****************************************************************************************
!/bin/bash
# **************** Change Variables Here ************
startdirectory="/your/start/directory"
searchterm="test"
replaceterm="test=ok!"
# **********************************************************
echo "***************************************************"
echo "* Search and Replace in Files Version 01-Aug-2012 *"
echo "***************************************************"
i=0;
for file in $(grep -l -R $searchterm $startdirectory)
do
cp $file $file.bak
sed -e "s/$searchterm/$replaceterm/ig" $file > tempfile.tmp
mv tempfile.tmp $file
let i++;
echo "Modified: " $file
done
echo " *** All Done! *** Modified files:" $i
SearchMonkey is a light-weight Gtk application that aims to replace the cumbersome find/grep with a slick user interface that quickly provides a mark-up showing locations and quantity of text matches. The goal is to provide a simple to use and accessible search tool for end-users, and software developers alike.
Here I use sed to replace every occurrence of the word "cybernetnews" with "cybernet" in every file with the extension, c, in the directory, /home/user/directory/.
A more generic variation where you search recursively from the directory of execution and operate on only regular, readable, writeable files:
The stream editor,sed, is a powerful utility for this kind of work and is my first choice, however, if you want to do this from an ordinary text editor using an Ubuntu based native application, I would suggest you take a look at Jedit, It is available in the repositories and can be installed by typing in your console:
Start jedit, click the search menu item, in the menu list, click the Search in Directory item, you will be presented with the dialog below:
This is similar to that of Notepad++ and does the same thing, I believe this is what you want.
Another GUI option is regexxer:
replaces any occurence of oldtext by newtext in all files in the current folder. However you will have to escape all perl special characters within oldtext and newtext using the backslash.
Check with Geany, it is perfect NPP replacement for Linux. You can do exactly that plus you can use regex.
A very simple solution: replace in all
*.txt
files in folderstring_1
withstring_2
:I wrote a little script for just this thing. If you only need the basics and are not familiar with sed etc, take a look here: http://www.csrdu.org/nauman/2010/12/30/bash-script-to-find-and-replace-in-a-set-of-files/
The script is the following:
You can use this script, copy code and make a file
find_and_replace_in_files.sh
.I have modified it a little; please tell me your opinion.
works for me on fedora
Another program is Searchmonkey.