I have lots of .dat file and I want to convert them to .sac file (a type of seismogram file). I convert files with xy2sac program (I didn't write the code), but I have to give converted files a new name which I pick.
The converter code works like this:
xy2sac filename.dat newfilename.sac
What I want to do is giving my new file names while xy2sac program is working in a loop. For example my dat file names are like this:
BRGA_KO_disp_post_mij_conv0000_E.dat
BRGA_KO_disp_post_mij_conv0000_E.dat
BRGA_KO_disp_post_mij_conv0000_N.dat
BRGA_KO_disp_post_mij_conv0000_Z.dat
GADA_KO_disp_post_mij_conv0000_E.dat
GADA_KO_disp_post_mij_conv0000_N.dat
GADA_KO_disp_post_mij_conv0000_Z.dat
HYBL_KO_disp_post_mij_conv0000_E.dat
HYBL_KO_disp_post_mij_conv0000_N.dat
HYBL_KO_disp_post_mij_conv0000_Z.dat
ISK_KO_disp_post_mij_conv0000_E.dat
ISK_KO_disp_post_mij_conv0000_N.dat
ISK_KO_disp_post_mij_conv0000_Z.dat
TUZL_KO_disp_post_mij_conv0000_E.dat
TUZL_KO_disp_post_mij_conv0000_N.dat
TUZL_KO_disp_post_mij_conv0000_Z.dat
I want to change their name to:
BRGA_KO__E.sac
BRGA_KO__E.sac
BRGA_KO__N.sac
BRGA_KO__Z.sac
GADA_KO__E.sac
GADA_KO__N.sac
GADA_KO__Z.sac
HYBL_KO__E.sac
HYBL_KO__N.sac
HYBL_KO__Z.sac
ISK_KO__E.sac
ISK_KO__N.sac
ISK_KO__Z.sac
TUZL_KO__E.sac
TUZL_KO__N.sac
TUZL_KO__Z.sac
So I would like the pick first 8 characters and last character before the .dat.
How can I achieve that?
I use this loop but it didn't work, and I end up with .dat file extension.
foreach file (`ls *.dat*`)
xy2sac *.dat *.sac << END
END
end
Thanks in advance.