1752680 Members
5626 Online
108789 Solutions
New Discussion юеВ

Scripting help reqd

 
SOLVED
Go to solution
ShivKumar_1
Frequent Advisor

Scripting help reqd

Hi guys,
I have a set of files in a directory they are archieves from Oracle for eg;
*********************************************
/oracle/TRN/saparch
#ls -ltr
PRDarch1_32690.dbf
PRDarch1_32691.dbf
PRDarch1_32692.dbf
**********************************************
What I want to do is to rename the first 3 characters ie "PRD" to "TRN" and the rest of the things would remain the same so the out put would be

TRNarch1_32690.dbf
TRNarch1_32691.dbf
TRNarch1_32692.dbf

Is there a way to script it out?

Thnks
SK






7 REPLIES 7
Victor Fridyev
Honored Contributor
Solution

Re: Scripting help reqd

Hi,
Try the following:
#!/usr/bin/sh
cd DIRN
OLD=PRD
NEW=TRN

ls -1 ${OLD}*| while read FILENAME; do
NEWN=$(echo $FILENAME|sed "s/^$OLD/$NEW/")
mv $FILENAME $NEWN
done
Entities are not to be multiplied beyond necessity - RTFM
A. Clay Stephenson
Acclaimed Contributor

Re: Scripting help reqd

Of course there is a way to script this but I think it does you more harm than good to give you a full solution. This is really basic scripting that any admin should learn to do:

I'll get you started:

cd /oracle/TRN/saparch
ls PRDarch*.dbf | while read X
do
NEW=$(echo "${X}" | sed 's/^PRD/TRN/')
echo "${X} -> ${NEW}"
mv "${X}" "${NEW}"
done

I would probably add some testing to make sure that the new files does not already exist before doing the mv. The quotes are important because your filenames might contain whitespace.
If it ain't broke, I can fix that.
Marvin Strong
Honored Contributor

Re: Scripting help reqd

something like this should do it.


for prd in `ls /oracle/TRN/saparch`
do
trn=`echo $prd | sed 's/PRD/TRN/'`
mv $prd $trn
done


ShivKumar_1
Frequent Advisor

Re: Scripting help reqd

Hi guys
Thnks for the quick response.

Pl close this form.

Bart Paulusse
Respected Contributor

Re: Scripting help reqd

Is this realy what you want to do?
These are oracle's offline redolog files.
Changeing their name will make them invisible for oracle in case you need to recover your database.
Also the SAP tool brarchive won't be able to back them up.
If you've renamed your database/SAP instance you should also adjust the naming of you offline redo logfiles in $ORACLE_HOME/dbs/init.ora :

log_archive_dest='/oracle/TRN/oraarch/TRNarch'

regards,

Bart
ShivKumar_1
Frequent Advisor

Re: Scripting help reqd

Hi bart,
Thnks for your suggestion. The thing is we are doing a rcp from our production server to another server. So , the names need to be different in another system.

Thnks
SK
Bart Paulusse
Respected Contributor

Re: Scripting help reqd

Hi,

if you've renamed your database after the rcp to oyou will have pen your database with the RESETLOGS option. This means that old offline redolog files are unuseable.

If this is the case you can delete the old offline redologfiles instead of renaming them.

regards,

Bart