Linux command to change all values within files in an Oracle directory?
Oracle Database Tips by Donald Burleson
Question: What Linux or UNIX command can I use to change
all occurrences of a string within a directory? Do I use sed, awk, or
The sed command is used to make global changes to strings in UNIX files.
For example, below we have a utility that will change all strings in a
directory from one string to another. This is sort of a ?change all?
utility within UNIX. The format of the sed command is:
sed/oldstring/newstring > new file location
The sed utility always makes a new copy of every file it changes, so special
care is required to make an in-place change. Note the sed line in this
script where sed changes the old string to the new string in all files in
the directory. Note that this script makes a backup of the files in a tmp
sub-directory before issuing the change.
WARNING: This is a VERY POWERFUL script,
not to be used by beginners. Use this script at your own risk:
1 - copy-paste this script as chg_all.sh on your
server in the home directory where you wish to make cascading changes.
2 - Issue a chmod +x chg_all.sh to make it
3 - vi the file and change the oldstring and newstring
values. NOT you can put spaces in the command like so:
sed -e 's/ 2004 / 2015 /g' < $f > $tmpdir.new/$f
4 - Save the file from vi "<esc> : x" and execute the
chg_all.sh is below:
for f in $*
sed -e 's/oldstring/newstring/g' < $f > $tmpdir.new/$f
# Make a backup first!
mv $* $tmpdir.old/
mv $* ../
See my notes on Oracle directories here.
If you like Oracle tuning, see the book "Oracle
Tuning: The Definitive Reference", with 950 pages of tuning tips and
You can buy it direct from the publisher for 30%-off and get
instant access to the code depot of Oracle tuning scripts.