Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

BASH script: redirect file content to program

Posted on 2010-09-07
4
Medium Priority
?
402 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 68

Accepted Solution

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

0
 
LVL 14

Expert Comment

by:sentner
ID: 33617817
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
ID: 33617845
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
ID: 33625567
Perfect! Thanks a lot
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

618 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