InteractiveMind
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!
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
OH, sorry just saw that you needed one line per call to myprog.out. Please ignore my previous answer.
ASKER
Perfect! Thanks a lot
cat input.dat | ./myprog.out >>output.dat