1753611 Members
5881 Online
108797 Solutions
New Discussion юеВ

Replace

 
SOLVED
Go to solution
Prabhu_7
Frequent Advisor

Replace

I have more than 150 shell scripts.
I use a common environmental variable (PROCESS_DT) in all of them. Now i need to change it as PROCESS_DATE. Is there any way i can change in all scripts all at once ?

Thanks
Raj
5 REPLIES 5
Paula J Frazer-Campbell
Honored Contributor

Re: Replace

Hi

I dont have a server to check it on but this should create a backup of your file first and then do the replace.

Test it on a few files in a test environment first.

find . -type f -print | xargs perl -i.bak -p -e 's#/PROCESS_DT/#PROCESS_DATE#g'


Paula
If you can spell SysAdmin then you is one - anon
Helen French
Honored Contributor

Re: Replace

Try this script:

#!/usr/bin/ksh
find . -type f -depth | while read FILE
do
sed "s/PROCESS_DT/PROCESS_DATE/g" < ${FILE} > ${FILE}.shiju
mv ${FILE}.shiju $FILE
done
Life is a promise, fulfill it!
RAC_1
Honored Contributor
Solution

Re: Replace

Backup all you files.

for in in `ls -l|awk '{print $9}'`
do
sed "s/PROCESS_DT/PROCESS_DATE/g" $i > $.bak
mv $i.bak $i
done

There is no substitute to HARDWORK
Prabhu_7
Frequent Advisor

Re: Replace

I get the following error.

Usage:
mv [-f] [-i] [-e warn|force|ignore] f1 f2
mv [-f] [-i] [-e warn|force|ignore] f1 ... fn d1
mv [-f] [-i] [-e warn|force|ignore] d1 d2
Paula J Frazer-Campbell
Honored Contributor

Re: Replace

hi

use mv -f


Paula
If you can spell SysAdmin then you is one - anon