Well the title is not too good, so I will explain.
I need to move (rename) files using a simple AIX script.
???file1.txt
???file2.txt
???file1a.txt
???file2a.txt
to be:
???renamedfile1'date'.txt
???renamedfile2'date'.txt
???renamedfile1a'date'.txt
???renamedfile2a'date'.txt
The ??? are realy numbers 001 through 999, and there are two filenames per number. The 'date' is easy `date +%Y%m%d`. but due to my limited scripting ability, I cannot seem to get this accomplished.
Any help would be greatly appreciated.
Thanks in advance.
Something like this? Try it first without the coloured portion to see if you get the right commands:
ls ???file??.txt | sed "s/\(...\)\(.*\)\.\(.*\)/mv & \1renamed\2""`date +%Y%m%d`"".\3/" | sh
Regards
It works greatly on UBUNTU
ls ???file*.txt | sed "s/\(...\)\(.*\)\.\(.*\)/mv & \1renamed\2`date +%Y%m%d`.\3/" | sh
For whatever reason (did a copy and paste of the line into a script) this did not work. I only got one file with a `date +%Y%m%d`.txt
for f in *pepfilled.txt ; do
mv $f /usr/$fclaims`date +%y%m%d`.txt
done
Am I missing a quote(s) somewhere? The red claims above is the new file name with a format of ???claims20081220.txt, renamed from ???pepfilled.txt.
This will get half my files ???pepfilled.txt, I will just write the same script for the other half ???pepfilledcr.txt.
You provided weak examples, in your first post, of the input and the desired output. Try this:
ls ???pepfilled*.txt | sed "s/\(...\).*\.\(.*\)/\1claims`date +%Y%m%d`.\2/" | sh
Regards