Mike F Mike F - 1 year ago 72
Bash Question

creating bash script to automate task for analyzing multiple files

I don't have a lot of experience with scripting.

I have a directory that contains, among many other files, a set of

files I need to analyze with a program. I would like to automate this task. I think a loop bash shell script would be appropriate, although I could be wrong.

If I was to perform the analysis manually on one
file, I would use the following command in terminal:

./raxmlHPC-SSE3 -m GTRCAT -y -s uce-5.phylip --print-identical-sequences -p 12345 -n uce-5_result

For the bash shell script, I think it would be close to:

for i in $( ls ); do
./raxmlHPC-SSE3 -m GTRCAT -y -s uce-5.phylip --print-identical-sequences -p 12345 -n test_5 $i

The issue I'm aware of, but don't know how to fix, is the -s option, which specifies the input phylip file. Any suggestions on how to modify the script to do what I need done?

Answer Source

Try the below code:

for i in *.phylip
    ./raxmlHPC-SSE3 -m GTRCAT -y -s "$i" --print-identical-sequences -p 12345 -n ${i%.phylip}_result

-s option will be passed $i which has the file name with .phylip extension in the current directory.

${i%.phylip}_result replaces the .phylip extension with _result which i guess is what you expect. (Ref: Parameter Substitution)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download