Johnny
Johnny

Reputation: 13

Using Bash script to run multiple files through java code

I have some code that is used to analyse files, the code is setup to analyse 1 file at a time using the following command line input in the /home/john/Dropbox/PhD/MultiFOLDIA/ directory:

java MultiFOLDIA_IMODE1 complex.1.pdb /home/john/Dropbox/PhD/MultiFOLDIA/Poses/ T0868_T0869 /home/john/Dropbox/PhD/MultiFOLDIA/T0868_T0869_complex.1.pdb_IMODE1.txt > /home/john/Dropbox/PhD/MultiFOLDIA/MultiFOLDIA_IMODE1.log

I would like to run the command on every file in the /home/john/Dropbox/PhD/MultiFOLDIA/Poses/ directory and have tried using the following script:

#!/bin/bash

poses=(~/home/john/Dropbox/PhD/MultiFOLDIA/Poses/*)

for f in "${poses[@]}"; do
java MultiFOLDIA_IMODE1 "$f" /home/john/Dropbox/PhD/MultiFOLDIA/Poses/ T0868_T0869 /home/john/Dropbox/PhD/MultiFOLDIA/T0868_T0869_"$f"_IMODE1.txt > /home/john/Dropbox/PhD/MultiFOLDIA/MultiFOLDIA_IMODE1.log
done

It doesn't work and I think I am not understanding how to pull filenames from arrays and utilise them in this way.

Upvotes: 1

Views: 201

Answers (2)

pato
pato

Reputation: 908

This should work.

find /home/john/Dropbox/PhD/MultiFOLDIA/Poses/ -maxdepth 1 -type f -exec java MultiFOLDIA_IMODE1 '{}' /home/john/Dropbox/PhD/MultiFOLDIA/Poses/ T0868_T0869 /home/john/Dropbox/PhD/MultiFOLDIA/T0868_T0869_'{}'_IMODE1.txt >> /home/john/Dropbox/PhD/MultiFOLDIA/MultiFOLDIA_IMODE1.log \; 

Also, when redirecting output use >> instead of >. > truncate file and in the end you will have only logs from last execution eg:

$ echo a > test.txt
$ echo a > test.txt
$ cat test.txt
a

$ echo a >> test.txt
$ echo a >> test.txt
$ cat test.txt
a
a

Upvotes: 1

Eric Duminil
Eric Duminil

Reputation: 54263

~/ is already /home/john.

So ~/home/john probably doesn't exist.

This should bring you closer to your goal :

cd /home/john/Dropbox/PhD/MultiFOLDIA/Poses/

for pdb in *.pdb
do
  echo "Processing $pdb"
  java MultiFOLDIA_IMODE1 "$pdb" ./ T0868_T0869 ../T0868_T0869_"$pdb"_IMODE1.txt >> ../MultiFOLDIA_IMODE1.log
done

Upvotes: 1

Related Questions