Friday, July 22, 2005

multiple successive inputs

Michael Tosch Jul 19, 2:57 pm show options

Subject: Re: multiple successive inputs

Edwina Mackay wrote:
> Dear all,

> I am not well-versed in shell scripting so this is probably an easy
> question. I'm using a homemade C program given to me by a colleague, which
> I invoke with some options, like this:

> ./myprogram -n -g 2

> and the program responds:

> Please enter input set:

> to which I reply something like:

> 0,3,8,12

> and it spews out the required answer.

> I would like to run the program, with the same option set, on many input
> sets, without having to sit there and type them in one after the other on
> multiple runs of the program. Let's say I create a file of input sets that
> I want to run the program on, and this file looks like this:

> 0,3,8,12
> 0,3,11,14
> 0,2,5,6
> 0,2,8,11
> 0,2,7,13

> How do I now run the program on the whole list of input sets? I want
> something like (pseudocode):

> for each LINE in myfile do
> ./myprogram -n -g -2 [enter] LINE [enter] done

> Many thanks for helping me out with this. Best wishes, Edwina.

First try
./myprogram -n -g 2 <myfile

If this does not work then run this executable script:

#!/bin/sh
while read line; do
echo $line | ./myprogram -n -g -2
done <myfile

--
Michael Tosch @ hp : com

ITYM:

echo "$line" | ./myprogram -n -g -2
or
printf "%s\n" "$line" | ./myprogram -n -g -2

I know there's no spaces or special characters in the posted input
sample, but quoting by default is a good habit to get into.

Ed.

0 Comments:

Post a Comment

<< Home