Changing file names

sac_pzs_iv_epoz_hhe__2013.074.14.40.46.0000_2599.365.23.59.59.99999
sac_pzs_iv_epoz_hhn__2013.074.14.40.46.0000_2599.365.23.59.59.99999
sac_pzs_iv_epoz_hhz__2013.074.14.40.46.0000_2599.365.23.59.59.99999
sac_pzs_iv_haga_hhe__2006.111.00.00.00.0000_2599.365.23.59.59.99999
sac_pzs_iv_hpac_hhe__2012.326.14.06.31.0000_2599.365.23.59.59.99999
sac_pzs_iv_hpac_hhz__2012.326.14.06.31.0000_2599.365.23.59.59.99999

I want to remove the sac_pzs_ from the start and use extension .sac.pzs
Have been thinking of using rename. Want to get

iv_epoz_hhe__2013.074.14.40.46.0000_2599.365.23.59.59.99999.sac.pzs
iv_epoz_hhn__2013.074.14.40.46.0000_2599.365.23.59.59.99999.sac.pzs
iv_epoz_hhz__2013.074.14.40.46.0000_2599.365.23.59.59.99999.sac.pzs
iv_haga_hhe__2006.111.00.00.00.0000_2599.365.23.59.59.99999.sac.pzs
iv_hpac_hhe__2012.326.14.06.31.0000_2599.365.23.59.59.99999.sac.pzs
iv_hpac_hhz__2012.326.14.06.31.0000_2599.365.23.59.59.99999.sac.pzs
for i in sac_pzs_* ; do mv $i ${i#sac_pzs_}.sac.pzs ; done

Try:

for i in sac_pzs_*
do
   mv "$i" "${i#sac_pzs_}.sac.pzs"
done
1 Like
a=sac_pzs
b=.${a/_/.}
for i in ${a}_iv_*
do
   mv "$i" "${i/$a/}$b"
done