0

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

1
  • can you edit your question to specify which shell type? bash? other? Commented Nov 16, 2016 at 18:24

2 Answers 2

1
#!/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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.