shaq shaq - 9 months ago 26
Bash Question

removing a part of filename of a bunch of files

I want to remove test.extra from all of my file names in current directory

for filename in *.fasta;do

echo $filename | sed \e 's/test.extra//g'

done


but it complains about not founding file.echo is to be sure it list correctly.

Answer Source

First of all use 'sed -e' instead of '\e'

And I would suggest you do it this way in bash

for filename in *.fasta; do 
    [ -f "$filename" ] || continue
    mv "$filename" "${filename//test.extra/}"

done