Reputation: 3
I have a c++ executable file 'Score' that takes as input two user defined 'values'. These values are some data in txt files. I run the program and save the output to a text file like this :
./Score data1.txt data2.txt >outdata1data2.txt
Because I need to run this for many times would be possible to create a shell bash script that does this automatically something like :
./Score data1.txt data3.txt >outdata1data3.txt
./Score data1.txt data4.txt >outdata1data4.txt
and so on..
The names of the data are all different and all in the same directory as the executable file. My knowledge in C++ is very limited and any help would be appreciated
Upvotes: 0
Views: 311
Reputation: 365
It is definitely possible. You will probably want to write a shell script similar to this:
#!/bin/bash
for filename1 in /*.txt; do
for filename2 in /*.txt; do
./Score "$filename1" "$filename1" > "out$filename1$filename2"
done
done
Upvotes: 0
Reputation: 362187
#!/bin/bash
for dataFile in data*.txt; do
# Ignore data1.txt.
[[ $dataFile == data1.txt ]] && continue
./Score data1.dxt "$dataFile" > "outdata1$dataFile"
done
This loops over files named data*.txt
in the current directory. Since that matches data1.txt
, it needs to be explicitly ignored. It then calls ./Score
with each matching file name and names the output file based on the input file.
Upvotes: 1