0

In a bash shell, i want a script or commands that will take all test.in files (i have test1.in, test2.in, test3.in, to testN.in) and pipe it to an executable testExecutable and output the results of each in a testN.out file.

So far, I know i can input all the files by doing find . test*.in < testExecutable

but I"m not sure how to do the output pipe to generate mytest1.out for test1.in and mytest2.out for test2.in and so on.

Thanks for help in advance.

1 Answer 1

1

You need a loop:

for f in test*.in; do testExecutable <"$f" >"my${f%in}out"; done

The above is safe for all file names, even names containing white space.

2
  • 1
    Thanks for replying, that was exactly what i wanted! Now i'm trying to diff the mytest1.out and test1.out's for all testN's, would it be something like this? I want to make diff1.txt, diff2.txt, etc... for f in test*.in; do diff "$f" "my${f%in}out" > "diff$${f%in}"; done`
    – raisinpon
    Oct 29, 2015 at 0:59
  • Yes, but replace "diff$${f%in}" (where the $$ will not work as you want) with "diff${f%in}txt" and the output files will be named diffmytest1.txt, etc.
    – John1024
    Oct 29, 2015 at 1:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.