2

I have a list of files with a common name pattern, all with the same structure (prefix ave.):

ave.20050716-12:00:00.stat_profiles.nc 
ave.20050816-12:00:00.stat_profiles.nc  
ave.20081116-00:00:00.stat_profiles.nc  
ave.20120215-12:00:00.stat_profiles.nc
ave.19990316-12:00:00.stat_profiles.nc  
ave.20020616-00:00:00.stat_profiles.nc  

My question is: How do I remove ave. from all the files in a file list / folder?

PEBKAC
  • 748
  • 1
  • 9
  • 28
  • @Corion, I'm sorry, I really don't know how to apply it to my concrete solution. I'm completely new at this! – PEBKAC Oct 25 '18 at 14:30
  • Then work through the parts of the answer I linked, try them, and maybe ask us with a concrete failing example where it fails to work. – Corion Oct 25 '18 at 14:31

2 Answers2

3

You can use a for loop and string substitution

for file in ave.*
do 
    mv "$file" "${file#ave.}"
done

This is just an example to get you started and you should check for things such as already existing files with the name without "ave.".

tripleee
  • 175,061
  • 34
  • 275
  • 318
Alex M
  • 885
  • 9
  • 12
0

If you have the rename utility from the util-linux package available, it makes this kind of task very easy.

From its man :

  rename [options] expression replacement file...

rename will rename the specified files by replacing the first occurrence of expression in their name by replacement.

So in your case :

rename ave. '' ave.*
Aaron
  • 24,009
  • 2
  • 33
  • 57