Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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.txtThen 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!

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 scriptAn alternative solution is using the unix split command and divide data-file into 25 separate files and use them for input.

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

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

#!/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

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.

![]() |
Awk script
|
need help with grep....
|

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