for, do, done applying in convert txt to biom format in linux

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

1 answer

  • answered 2019-01-11 06:05 tink

    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.