Solved

BASH script: redirect file content to program

Posted on 2010-09-07
4
399 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 500 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Linux Hosting 16 102
CentOs root password/fsck issue 7 58
check the file dates in unix 14 73
Unbreakable Oracle Linux 6.8 installation problem 9 57
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

738 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