Solved: batch file to read and run input file

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

maa3

Thread Starter
Joined
Jan 11, 2013
Messages
15
Hi, just joined the forum. I am new to programming. Could someone please help me write a batch file that will run an executable file A.exe say 100 times, each time using an input data file case1.dat. The input data also varies by picking up coresponding material properties from concrete.dat and steel.dat.
Sample input file is:
Input.dat
Element type
1,1,1,0,0,0
Concrete props
1,5.2,4110.0,0.2
Steel props
1,68.9,103.6,33
Output
1,2,3
end
Typical concrete.dat and steel.dat files may have say 100 corresponding article lines each, to be placed specifically in say lines 4 and 6 of input.dat for each run of A.exe.
I would be grateful if someone could please help me with this batch file using dos. I do not know how to program in visual basic so hope to get it done in dos.
Typical concrete.dat file;
1,5.2,4110.0,0.2
1,5.0,4125.0,0.23
1,3.5,3298.0,0.15
etc up to 100 lines and
that of steel.dat file:
1,68.9,103.6,33.0
1,56.4,100.2,45.0
1.2,89.1,101.1,40.0
etc up to 100 lines.
Thanks and hope to get help.
 

Squashman

Retired Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
I am not understanding how this all links together. You have 3 text files. What are you expecting the output to be?
What is the real name of your executable? That may help us as well.
 

foxidrive

Banned
Joined
Oct 20, 2012
Messages
793
It seems to me as though the task is to take one data file "case1.dat"
and in lines 4 and 6 he wants to replace each line from two other files.

So the first run takes line 1 from steel and concrete files and puts them in lines 4 and 6 , the 2nd run takes line 2 from steel and concrete files and puts them in lines 4 and 6, and so on.
 

maa3

Thread Starter
Joined
Jan 11, 2013
Messages
15
That's exactly what I need to do. The executable is a fortran program which has been compiled to analyse buildings.
 

foxidrive

Banned
Joined
Oct 20, 2012
Messages
793
This is untested.

a.exe should be able to take casetmp.dat as an argument.
It uses GnuSED.
The two lines that are being replaced must be unique in the case1.dat and are also case sensitive.


If it has issues then reply here.

EDITED: to fix a syntax error

Code:
@echo off
for /L %%a in (1,1,100) do call :next %%a
echo done
pause
goto :EOF

:next
for /f "delims=" %%b in ('sed %1!d concrete.dat') do set "four=%%b"
for /f "delims=" %%c in ('sed %1!d steel.dat') do set "six=%%c"
sed -e "s/^Concrete props$/%four%/" -e "s/^Steel props$/%six%/" case1.dat >casetmp.dat
a.exe casetmp.dat
del casetmp.dat
 

maa3

Thread Starter
Joined
Jan 11, 2013
Messages
15
This is untested.

a.exe should be able to take casetmp.dat as an argument.
It uses GnuSED.
The two lines that are being replaced must be unique in the case1.dat and are also case sensitive.


If it has issues then reply here.

EDITED: to fix a syntax error

Code:
@echo off
for /L %%a in (1,1,100) do call :next %%a
echo done
pause
goto :EOF
 
:next
for /f "delims=" %%b in ('sed %1!d concrete.dat') do set "four=%%b"
for /f "delims=" %%c in ('sed %1!d steel.dat') do set "six=%%c"
sed -e "s/^Concrete props$/%four%/" -e "s/^Steel props$/%six%/" case1.dat >casetmp.dat
a.exe casetmp.dat
del casetmp.dat
Thanks so much. I tried your suggestion and appears to be working to an extent. I tried 5 iterations and the program run 5 times. However, I realised the the same output file was obtained because an output file CYC1.dat in the input file remained the same. So I tried to introduce another statement to read in "CYC1.dat, CYC2.dat etc' to be inserted on line 88 but still got only CYC1.dat. I am not sure of the syntax for reading the string characters in this case.
The following message however appeared after each run for all 'sed' statements:
"[ 'sed' is not recognised as an internal or external command operable program or batch file.]"

The batch file I used is shown below and hope you could help me edit, thanks.

@echo off
for /L %%a in (1,1,5) do call :next %%a
echo done
pause
goto :EOF
:next
for /f "delims=" %%b in ('sed %1!d concrete.dat') do set "twenty-one=%%b"
for /f "delims=" %%c in ('sed %1!d steel.dat') do set "twenty-three=%%c"
for /f "delims=" %%d in ('sed %1!d output.dat') do set "eighty-eight=%%d"
sed -e "s/^CONCRETE PROPERTIES$/%twenty-one%/" -e "s/^STEEL PROPERTIES$/%twenty-three%/" -e "s/%eighty-eight%/" case1.dat >casetmp.dat
idarc2d_6.0.exe casetmp.dat
del casetmp.dat
 

foxidrive

Banned
Joined
Oct 20, 2012
Messages
793
I'm not sure that you follow the logic flow - do you have a file called output.dat

What is on line 88 in case1.dat?

As for sed, you have to download GnuSED for Windows. It is a free tool.
 

maa3

Thread Starter
Joined
Jan 11, 2013
Messages
15
Thanks. Didn't know about Gnused so will find it.
Line 88 contains only the file name CYC1.dat which is being read from output.dat. So CYC.dat is also numbered up to 100 and stored in output.dat. Once those file names are placed on line 88 of case1.dat, Idarc.exe will have a means of producing that file to store results of say the 48th run as CYC48.DAT.
 

maa3

Thread Starter
Joined
Jan 11, 2013
Messages
15
Thanks. Didn't know about Gnused so will find it.
Line 88 contains only the file name CYC1.dat which is being read from output.dat. So CYC.dat is also numbered up to 100 and stored in output.dat. Once those file names are read and placed on line 88 of case1.dat, Idarc.exe will have a means of producing that file to store results of say the 48th run as CYC48.DAT.
 

foxidrive

Banned
Joined
Oct 20, 2012
Messages
793
Try this: where "CYC1.dat" is case sensitive too, and should exist on line 88 of case1.dat file.

Code:
@echo off
for /L %%a in (1,1,5) do call :next %%a
echo done
pause
goto :EOF
:next
for /f "delims=" %%b in ('sed %1!d concrete.dat') do set "twenty-one=%%b"
for /f "delims=" %%c in ('sed %1!d steel.dat') do set "twenty-three=%%c"
for /f "delims=" %%d in ('sed %1!d output.dat') do set "eighty-eight=%%d"
sed -e "s/^CONCRETE PROPERTIES$/%twenty-one%/" -e "s/^STEEL  PROPERTIES$/%twenty-three%/" -e "s/^CYC1.dat$/%eighty-eight%/" case1.dat  >casetmp.dat
idarc2d_6.0.exe casetmp.dat
del casetmp.dat
 

maa3

Thread Starter
Joined
Jan 11, 2013
Messages
15
Sorry to be a bother. I got the GNUSED tool and installed but doesn't seem to work on Windows 7. It is in my start up but cannot get to open it as an executable file. I have used several hours reading about it today but not sure whether GNUSED windows requires a path to be used in the set up other than the program files directory. I downloaded sed_4.2.1-setup for the installation. Can anyone please help me with this? I am entirely new to this area.
 

foxidrive

Banned
Joined
Oct 20, 2012
Messages
793
It is a command line program and just has to be available on the path, or replace the lines with sed in them to the correct path and filename, like "c:\program files\gnused\bin\sed.exe"

One way to put it on the path is to copy the sed.exe and any support DLL files to c:\windows\ and then that should be on the path. Open a cmd prompt and type SED and you should get help screen messages if all is well.
 

maa3

Thread Starter
Joined
Jan 11, 2013
Messages
15
I tried and got the help messages alright. However when I tried the command line with the script input, the following message appeared:
sed: -e expression #1 char 6: unterminated 's' command
 

foxidrive

Banned
Joined
Oct 20, 2012
Messages
793
Can you copy and paste the script again? I tested it in a limited fashion and it seems to work fine here.
 

maa3

Thread Starter
Joined
Jan 11, 2013
Messages
15
Can you copy and paste the script again? I tested it in a limited fashion and it seems to work fine here.
I copied and pasted script again but still same result. Just in case I am on the wrong path,please check the command I used:
C:\Program Files\GnuWin32\bin\sed script final.txt
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top