Link to home
Start Free TrialLog in
Avatar of InteractiveMind
InteractiveMindFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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!
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or simpler, since all you're doing is redirecting the lines to stdout anyway:

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


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

Avatar of InteractiveMind

ASKER

Perfect! Thanks a lot