BASH script: redirect file content to program

Hi, I have a C program which reads in two integers from the user, like so:

  int A, B;
  scanf("%i %i",&A,&B);

it then does some magic and outputs a line of numbers which I need to redirect to a file. Currently, I'm doing this like so:

  echo $A $B | ./myprog.out >> output.dat

Now, however, I have a file called input.dat, which contains two columns of integers separated by a tab. I require a script that will go through each line in this file and do the above (pipe the numbers in, redirect the output to a file). I imagine this is easy, but I have no experience with Linux scripting...so, pretty please?

Thanks!
LVL 25
InteractiveMindAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
woolmilkporcConnect With a Mentor Commented:
while read A B ; do echo $A $B | ./myprog.out >> output.dat ; done < input.dat
wmp

0
 
sentnerCommented:
Or simpler, since all you're doing is redirecting the lines to stdout anyway:

cat input.dat | ./myprog.out >>output.dat


0
 
sentnerCommented:
OH, sorry just saw that you needed one line per call to myprog.out.  Please ignore my previous answer.

0
 
InteractiveMindAuthor Commented:
Perfect! Thanks a lot
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.