Need to move and rename a list of files

Hi,

I need to do something easy but I can't seem to figure out how to do this.

Let's say I have 6 files in the directory below:
/ebsbeta_f/flash/EBSUATQB/onlinelog
o1_mf_6_55klt7nr_.log
o1_mf_3_55klskj4_.log
o1_mf_4_55klsrl1_.log
o1_mf_5_55klt09p_.log
o1_mf_2_55klv1ts_.log
o1_mf_1_55kmbl9l_.log

And I would like to move and rename these to /ebssand/oradata
o1_mf_6_55klt7nr_.log -> log06.dbf
o1_mf_3_55klskj4_.log -> log03.dbf
o1_mf_4_55klsrl1_.log -> log04.dbf
o1_mf_5_55klt09p_.log -> log05.dbf
o1_mf_2_55klv1ts_.log -> log02.dbf
o1_mf_1_55kmbl9l_.log -> log01.dbf

I know I can create a manual script $ mv a b, but I would like to know how I can automate this with a wrapper that read the source files and moves&renames these to the destination location in case more files are added to this list.

Thanks!
Mark

You can try something like:

ls o1_mf_*.log | 
awk -F"_" '{system("mv "$0 " /ebssand/oradata/" sprintf("log%.2d.dbf",$3))}'

Regards

Thanks for the prompt response, but I'm getting this:

orabeta@hafindb01q: /home/orabeta $ ls /ebsbeta_f/flash/EBSUATQB/onlinelog/o1_mf_*.log | awk -F"_" '{system("cp "$0 " /ebssand/oradata/" sprintf("log%.2d.dbf",$3))}'

cp: /ebssand/oradata/log00.dbf: The file access permissions do not allow the specified action.
cp: /ebssand/oradata/log00.dbf: The file access permissions do not allow the specified action.
cp: /ebssand/oradata/log00.dbf: The file access permissions do not allow the specified action.
cp: /ebssand/oradata/log00.dbf: The file access permissions do not allow the specified action.
cp: /ebssand/oradata/log00.dbf: The file access permissions do not allow the specified action.
cp: /ebssand/oradata/log00.dbf: The file access permissions do not allow the specified action.
cp: /ebssand/oradata/log00.dbf: The file access permissions do not allow the specified action.
cp: /ebssand/oradata/log00.dbf: The file access permissions do not allow the specified action.
cp: /ebssand/oradata/log00.dbf: The file access permissions do not allow the specified action.
cp: /ebssand/oradata/log00.dbf: The file access permissions do not allow the specified action.
cp: /ebssand/oradata/log00.dbf: The file access permissions do not allow the specified action.
cp: /ebssand/oradata/log00.dbf: The file access permissions do not allow the specified action.

Do you have write permission in the destination directory? Does it work if you change the directory to the location of the files?

cd /ebsbeta_f/flash/EBSUATQB/onlinelog
ls o1_mf_*.log | 
awk -F"_" '{system("mv "$0 " /ebssand/oradata/" sprintf("log%.2d.dbf",$3))}'

Regards

Thank you; that worked!

---------- Post updated at 02:58 PM ---------- Previous update was at 02:43 PM ----------

One more question (and I thought I could figure it out on my own using your code but I can't :frowning: ):
Let's say I want to copy - without renaming - the following 3 files: /ebsbeta/oradata/cntrl01.dbf, /ebsbeta/oradata/cntrl02.dbf, /ebsbeta/oradata/cntrl03.dbf to /overflow. How can I make a loop to copy any cntrl* files?

Why don't you use an ordinary cp command, you don't need awk for this if you place all the commands in a script.

cp cntrl*.dbf /overflow

Regards

My bad. I want to copy AND rename them... I want to append beta_ to the copied files...

You can use a shell loop but it's shorter with awk:

ls cntrl*.dbf | awk '{system("cp " $0 " /overflow/beta_" $0)}'
ls -1 cntrl*.dbf | sed 's~.*~cp & /overflow/&_beta~' | ksh

---------- Post updated at 03:53 PM ---------- Previous update was at 03:48 PM ----------

Ooops...did not realize Franklin had responded.
Also, thought you wnated beta at the end.
To set things right:

ls -1 cntrl*.dbf | sed 's~.*~cp & /overflow/beta_&~' | ksh
OIFS=$IFS
for i in dir1/*.log;do
IFS="_"
set $i
file="log"${3}".dbf"
IFS=$OIFS
cp $i dir2/$file
done

Thank you all!