0

I have a lot of files like this:

2007.365.00.00.00.0000.9A.CVSV4..HHZ.D.SAC.GAP.decim10.GAP

In the end I want it like:

2007.365.00.00.CVSV4.HHZ.SAC

I tried this:

for file in /home/joana/Desktop/*GAP; do
mv "$file" `echo "$file" | sed -e 's/00.0000.9A.//' -e 's/.D//' -e 's/.GAP.decim10.GAP//'`;
done

Anda I get this:

mv: cannot move ‘/home/joana/Desktop/2007.365.00.00.00.0000.9A.CVSV4..HHZ.D.SAC.GAP.decim10.GAP’ to ‘/home/joanaesktop/2007.365.00.00.CVSV4..HHZ.D.SAC’: No such file or directory

Anyone can help me? I saw a lot of examples but I am probably doing something wrong.

closed as unclear what you're asking by heemayl, GAD3R, techraf, Archemar, HalosGhost Oct 12 '16 at 13:51

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Renaming based on what? – heemayl Oct 12 '16 at 9:55
  • your send command removes the D in Desktop also /home/joanaesktop/200 – Kamaraj Oct 12 '16 at 10:10
3

if you are happy with the output, then remove the echo (before the mv)

 for file in *GAP 
    do 
        NEW_FILE=$(echo ${file} | awk -F. '{print $1,$2,$3,$4,$8,$10,$12}' OFS=.)
        echo mv ${file} ${NEW_FILE}
     done
  • Many many thanks. It worked perfectly. I just took out the echo before the mv. – Joana Carvalho Oct 12 '16 at 13:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.