Computing.Net > Forums > Unix > Getting Input To Work Correctly

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Getting Input To Work Correctly

Reply to Message Icon

Name: natnit
Date: April 5, 2006 at 12:48:56 Pacific
OS: Windows XP
CPU/Ram: 1 gig
Product: homemade?
Comment:

Hey guys, I'm trying to write a Unix shell to streamline some work I have for a research project, but getting this last bit to work is driving me crazy.

To start, there are three files.

Program: This is a program, that in the course of running, prompts the user once for input file, and then for the output file. Treat it as a black box...it does exactly what it's supposed to if fed the right information.

Data file: Contains a list of the various inputs and output files, and there are 50 of each. Let's just say that it looks something like this:

in01.txt
out01.txt
in02.txt
out02.txt
...
in50.txt
out50.txt

Then the final part, which I'm having most trouble, is the actual shell that I was hoping would make this all work. The code within the shell looks like this.

#!/bin/sh
program < Data-file < Date-file
program < Data-file < Data-file
...
program > Data-file < Data-file (up through 50 times)

Now, what I want it to do, is to go sequentially through the data-file, and run it on each pair of input/output. What I believe it is doing is simply running the program from in01.txt and out01.txt 50 times, leaving the other inputs and outputs untouched.

Thanks for any feedback. This is driving me completely bonkers, and hopefully someone with more experience can just guide me in the right direction.

Thanks!



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: April 5, 2006 at 13:44:36 Pacific
Reply:

How about settup up a loop reading data-file twice sending the output to an intermediate file; then execute 'program' using the intermediate file for input:

#!/bin/sh

cnt=0
rm -f intermediate.file
while read line
do
echo "$line" >> intermediate.file
cnt=`expr $cnt + 1`
if [ $cnt = 2 ]
then
cnt=0
program < intermediate.file
rm -f intermediate.file
fi
done < data-file
#end script

An alternative solution is using the unix split command and divide data-file into 25 separate files and use them for input.


0

Response Number 2
Name: natnit
Date: April 5, 2006 at 15:58:25 Pacific
Reply:

Wow, thanks so much. I went with the tempfile way (cleaner that making a ton more files in an already cluttered folder) and it works like a charm. Seems to be working thus far, hehe.

Thanks again,
natnit


0

Response Number 3
Name: natnit
Date: April 6, 2006 at 10:06:57 Pacific
Reply:

Hey, thanks again for the help, but I have one more question. How would I go about putting a counter, so that before "program" ran each time, I'd get a message like "Run 1" "Run 2" "Run 3" etc...?

-natnit


0

Response Number 4
Name: nails
Date: April 6, 2006 at 10:52:59 Pacific
Reply:

#!/bin/sh

cnt=0
mycnt=0
rm -f intermediate.file
while read line
do
echo "$line" >> intermediate.file
cnt=`expr $cnt + 1`
if [ $cnt = 2 ]
then
mycnt=`expr $mycnt + 1`
echo "Run $mycnt"
program < intermediate.file
cnt=0
rm -f intermediate.file
fi
done < data-file


0

Response Number 5
Name: natnit
Date: April 6, 2006 at 12:40:39 Pacific
Reply:

Thanks again nails. :) You're way too awesome.


0

Related Posts

See More



Response Number 6
Name: nails
Date: April 6, 2006 at 13:19:45 Pacific
Reply:

Natnit:

Thanks! Now, if I can just convince my boss I'm awesome <grin>


0

Response Number 7
Name: natnit
Date: April 7, 2006 at 17:06:11 Pacific
Reply:

For some reason I get the following error at around run 30...any input? I rechechked the data-file, but I couldn't find anything weird. Any ideas?:

./HELPER_HOMFLY.txt: line 15: 24989 Segmentation fault ./homfly1_21 -pp <intermediate.file

(./HELPER_HOMFLY.txt is the proggy, just to note)

Hehe, thanks again nails.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Awk script need help with grep....



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Getting Input To Work Correctly

can't get modem to dial on redhat 5.2 www.computing.net/answers/unix/cant-get-modem-to-dial-on-redhat-52/271.html

SCO Unix 5.0.6 printing to Windows 98 www.computing.net/answers/unix/sco-unix-506-printing-to-windows-98/3238.html

Getting PHP to work with PostgreSQL www.computing.net/answers/unix/getting-php-to-work-with-postgresql/4139.html