linux - Need help in batch renaming files with bash shell script -
i have 50+ files in following format :
abcd_vish_running_zebra_20140818.dat_08-14-2014_23:08:23<br> abcd_vish_running_zeb-ra_20140818.dat_08-14-2014_23:08:35<br> abcd_vish_running_zeb_ra_20140818.dat_08-14-2014_23:08:37<br> abcd_vish_running_ri-ng_20140818.dat_08-14-2014_23:08:42<br> abcd_vish_running_ring_20140818.dat_08-14-2014_23:08:45<br> abcd_vish_running_ri_ng_20140818.dat_08-14-2014_23:08:52<br>
(zebra,zeb-ra,zeb_ra,ri-ng,ring,ri_ng given show pattern)
i need rename above files following format :
abcd_vish_running_zebra_20140818.dat<br> abcd_vish_running_zeb-ra_20140818.dat<br> abcd_vish_running_zeb_ra_20140818.dat<br> abcd_vish_running_ri-ng_20140818.dat<br> abcd_vish_running_ring_20140818.dat<br> abcd_vish_running_ri_ng_20140818.dat <br>
now how achieve shell scripting ? i'm new scripting. kindly help.
cheers.
using rename:
rename 's/[.]dat_.*/.dat/' *.dat_*
using for
loop in bash:
for f in *.dat_*; echo mv -- "$f" "${f/%.dat_*/.dat}" done
remove echo
when confirmed.
using mmv
:
mmv "*.dat_*" "#1.dat"
Comments
Post a Comment