shaq shaq - 1 year ago 56
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'


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/}"

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download