Solved

BASH script: redirect file content to program

Posted on 2010-09-07
4
397 Views
Last Modified: 2012-05-10
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!
0
Comment
Question by:InteractiveMind
  • 2
4 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
Comment Utility
while read A B ; do echo $A $B | ./myprog.out >> output.dat ; done < input.dat
wmp

0
 
LVL 14

Expert Comment

by:sentner
Comment Utility
Or simpler, since all you're doing is redirecting the lines to stdout anyway:

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


0
 
LVL 14

Expert Comment

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

0
 
LVL 25

Author Closing Comment

by:InteractiveMind
Comment Utility
Perfect! Thanks a lot
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now