Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Getting Input To Work Correctly

Original Message
Name: natnit
Date: April 5, 2006 at 12:48:56 Pacific
Subject: Getting Input To Work Correctly
OS: Windows XP
CPU/Ram: 1 gig
Model/Manufacturer: 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!


Report Offensive Message For Removal


Response Number 1
Name: nails
Date: April 5, 2006 at 13:44:36 Pacific
Subject: Getting Input To Work Correctly
Reply: (edit)
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.


Report Offensive Follow Up For Removal

Response Number 2
Name: natnit
Date: April 5, 2006 at 15:58:25 Pacific
Subject: Getting Input To Work Correctly
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 3
Name: natnit
Date: April 6, 2006 at 10:06:57 Pacific
Subject: Getting Input To Work Correctly
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 4
Name: nails
Date: April 6, 2006 at 10:52:59 Pacific
Subject: Getting Input To Work Correctly
Reply: (edit)
#!/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


Report Offensive Follow Up For Removal

Response Number 5
Name: natnit
Date: April 6, 2006 at 12:40:39 Pacific
Subject: Getting Input To Work Correctly
Reply: (edit)
Thanks again nails. :) You're way too awesome.

Report Offensive Follow Up For Removal


Response Number 6
Name: nails
Date: April 6, 2006 at 13:19:45 Pacific
Subject: Getting Input To Work Correctly
Reply: (edit)
Natnit:

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


Report Offensive Follow Up For Removal

Response Number 7
Name: natnit
Date: April 7, 2006 at 17:06:11 Pacific
Subject: Getting Input To Work Correctly
Reply: (edit)
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.


Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Getting Input To Work Correctly

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




XP Installed to G?

exessive internet traffic

ZoneAlarm Question. Blocked Connect

Windows Live Messenger Problem

Delete $Uninstall after SP3 updates


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC