0

I want to search and identify multiple files, within a directory, having a particular file extension (.txt) and changing the extension to (.fasta). This is considering not changing the file itself, only the extension, and saving it with the new extension.

file1.txt --> file1.fasta
file3.txt --> file2.fasta
file3.txt --> file3.fasta
bretonics
  • 215

1 Answers1

0

This is easy using a simple for loop in the shell.

for f in *.txt; do
    mv "$f" "${f%.*}.fasta"
done

The ${f%.*} expands to the filename without the extension.

jordanm
  • 42,678
  • Thanks! Worked perfectly! Can you explain what the (mv "$f" "${f%.*}.fasta") part is actually doing? – bretonics Apr 17 '13 at 18:24
  • @macam ${f%.*} is the filename without the extension. It simply moves the file to the filename without the extension with ".fasta" appended to the end. See BashFAQ 73. – jordanm Apr 17 '13 at 18:25