1

I have a folder with a numbers of txt files, I would like to apply the for do do loop to convert them from txt to biom files, the following is what I did:

for txt in folder/*.txt
do biom convert -i $txt -o *.biom --to-hdf5
done

but I got a combined biom file.

How can I revise my above code, changing the multiple txt files to biom files, without changing the original file name?

like: test.txt to test.biom

Lennon Lee
  • 194
  • 1
  • 14

1 Answers1

2

The following should do the trick (assuming there are now spaces in the filenames):

for txt in folder/*.txt
do biom convert -i $txt -o  ${txt%.txt}.biom --to-hdf5
done

The bash substitution ${txt%.txt} strips .txt of the variable, and we tack .biom at the end.

tink
  • 14,342
  • 4
  • 46
  • 50