To remove a suffix from a variable when you use it, you can use this syntax:
Code:
${variablename%suffix}
So, for example:
Code:
for file in one.ct two.ct three.ct; do
echo "original: $file ; no suffix: ${file%.ct} ; new suffix: ${file%.ct}.seq"
done
Should output:
Code:
original: one.ct ; no suffix: one ; new suffix: one.seq
original: two.ct ; no suffix: two ; new suffix: two.seq
original: three.ct ; no suffix: three ; new suffix: three.seq
So lets say you are working in a directory with a bunch of .ct files, you can do your processing like this:
Code:
for file in *.ct; do
ct2b.pl "$file" > "${file%.ct}.seq"
done
I quoted the file names in case any of the .ct files contain a space in the name - without the quotes it would not work correctly.
Note this will probably overwrite any existing .seq file which has a prefix which exists with a .ct extension. I say probably because the behaviour of the > redirection operator depends on the
noclobber setting in the shell. If you want it so that existing files are not overwritten, you should first set noclobber:
When noclobber is set, re-directions which would otherwise replace existing files will fail.