Hello,
I have a directory which has the file names as
ap_boise_20091109.Z.20091110
ap_aero_20091020.Z.20091021
.
..
...
I have to remove the time stamp after which is present after Z. as there are thousands of file to do so, is there a simple way to rename those file in a single command or script.
result should be like for the above files as
ap_boise_20091109.Z
ap_aero_20091020.Z
Try:
for i in *.Z.*; do
mv "$i" "${i%.*}"
done
if you have Python 2.4+, you can use this script.
usage:
$ ls -1
ap_aero_20091020.Z.20091021
ap_boise_20091109.Z.20091110
$ filerenamer.py -p "(.*Z)\..*" -e "\1" -l "ap_*"
==>>>> [ /home/ap_boise_20091109.Z.20091110 ]==>[ /home/ap_boise_20091109.Z ]
==>>>> [ /home/ap_aero_20091020.Z.20091021 ]==>[ /home/ap_aero_20091020.Z ]
remove -l option to commit changes
rename command is not working, its says
hpomt73e:/u/bxsunda> rename s/Z./Z/ ap_*.Z.
ksh: rename: not found
isn't it obvious, either you don't have rename, or you may have installed into different path.
Another way
#!/bin/bash
awk 'BEGIN{
q="\047"
for(i=1;i<ARGC;i++){
file=ARGV
m=split(file,f,".")
cmd = "mv "q file q" "q f[1] q
print cmd
#system (cmd) #uncomment to use
}
}' ap*