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.
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
mv "$filename" "${filename//test.extra/}"
mv
(the "${filename//test.extra/}"
)? Looks like a regex, except the match and replacement are switched. Tried looking it up, but don't know how to find that through Google.
Try rename "extra.test" "" *
Or rename 's/extra.test//;' *
$ find
./extra.test-eggs.txt
./extra.testbar
./fooextra.test
./ham-extra.test-blah
$ rename "extra.test" "" *
$ find
./-eggs.txt
./bar
./foo
./ham--blah
Bareword "extra.test" not allowed while "strict subs" in use at (eval 2) line 1.
, try using this syntax instead: rename 's/extra.test//;' *
Sep 1, 2019 at 7:44
I know this thread is old, but the following oneliner, inspired from the validated answer, helped me a lot ;)
for filename in ./*; do mv "./$filename" "./$(echo "$filename" | sed -e 's/test.extra//g')"; done
Try the rename
command:
rename 's/test.extra//g' *.fasta
rename
command is that? I can't find one which supports sed-like replacement syntax.
perl-rename
- it follows this exact syntax and is very handy with regexps
rename 'test.extra' '' *.fasta
, with the arguments being the substring, what to replace it with, and which files to rename
$ mmv '*test.extra*.fasta' '#1#2.fasta'
This is safe in the sense that mmv
will not do anything at all if it would otherwise overwrite existing files (there are command-line options to turn this off).
// EXTENSION - File extension of files
// STRING - String to be Replace
for filename in *.EXTENSION;
do [ -f "$filename" ] || continue;
mv "$filename" "${filename//STRING/}";
done
In Kali linux rename command is rename.ul
rename.ul 'string-to-remove' 'string-to-replace-with' *.jpg
example: rename.ul 'useless-string' '' *.jpg This will delete useless-string from all the jpg image's filname.
\e
instead of-e
.