Ok. Thanks is now working with txt files with the word .txt instead of .fasta!
• 0 views
•
link
Hi i want to rename all files with a 1 in a directory where the script is
#!/bin/bash
for filename in *.fasta; do
[ -f "$filename" ] || continue
mv "$filename" "${filename//1/}"
done
But when I'm in /tmp and the execute filename.sh the filenames have still a 1 innit
Why?
ah yes sorry, that was the output , not my script. OK the message in german is clear. There is no file with the suffix *.fasta in the directory.
Ok. Thanks is now working with txt files with the word .txt instead of .fasta!
You can use rename. Depending on the version installed one of the commands below should do:
rename "1" "" *.fasta
rename "s/1//" *.fasta
The structure of the command is rename 's/search/replace/'
Log in to answer this question.
run this version; show us the output:
[root@lapt0p tmp]# bash filename.sh
Seems not to know the command fasta. How to fix it?
I can install a AUR package named fasta?! Is this command not part of the basic commands from bash?
What is your distro?
I replaced .fasta with .txt now it's editing all files with ending *.txt. I wasn't clear that the coder of this script want only modify fasta files.
How I do it if i want modifiy all files in a folder? A . instead of .txt or a simple ``?
instead of
for filename in *.fasta, you can usefor i in *orfor i in $(ls *). You can also usefind.I wrote
not
I posted only the output of the script.
I copied one to one your new script.
what are you trying to do? You do not need a loop here. Use rename.
I did with rename but I was curious about how I do with this bashscript. I try to understand the error of the script for what I want to do.
can you try this?
But this would remove all '1's in file names.