Need script for renaming and moving files one by one...

Dears,

I need your help!
I got a problem and found some workaround solution but I donno how to realize it.

I have a number of files (about 300 each day) and I need them to be renamed. All these files has fixed number of letters and name looks like this one:

BR80_04.20110615050000.20110615050000-000.ASCII

I need just add to the begining of the name "RC1." letters to get filename like:

RC1.BR80_04.20110615050000.20110615050000-000.ASCII

to get list of files I can use:

ls > /tmp/FileNames

but how to add "RC1." to all these files?

This is just first step.
Next step I need these files one by one moved to another directory.
One by one it is very important because after each moved file will go another script for parsing this file. After file will be parsed it will be deleted automatically. So, main problem is to move files one by one....

I will be VERY happy if somebody will be able to help me.

Thanks to all in advance...

1) copy the file

 
for i in *; do cp $i RC1.$i; done

2) move the file

 
for i in RC1.*; do mv $i destination/directory/ ; done
1 Like

Hi itkamaraj,

first solution works just perfect!

When I am trying to run second one, I am getting error:

bash-3.00$ for i in RC1.*; do mv $i /tmp/2/ ; done
mv: cannot rename RC1.BR80_12.20110615000000.20110615000000-000.ASCII to /tmp/2/: Not a directory
mv: cannot rename RC1.BR80_12.20110615010000.20110615010000-000.ASCII to /tmp/2/: Not a directory
mv: cannot rename RC1.BR80_12.20110615020000.20110615020000-000.ASCII to /tmp/2/: Not a directory

How about this?

ls BR80* | xargs -i mv {} /destin/dir/RC1.{}

check do you have the directory called 2 under the /tmp

if it is not there, then create it and issue the command

Yes, sorry it was my mistake...
Its working but I need it to moving to another directory with another way.
After moving one file to (for e.g.) to /tmp/2 directory, will be invoked another script for parsing this file. AFTER this file parsed, next file moving to the same directory and same script for pasring running again.....

Is it possible to realize like that?

 
for i in RC1.*
do 
mv $i destination/directory/
if [ "$?" -eq "0" ]
then
 /call/the/script/here
 wait
fi
done
1 Like

Dear all,

Thanks to all for your help!
itkamaraj - that was exactly what I needed!
I spend so many days to load these files manually omg... )))
Thanks once more time!