need help writing a simple batch file to read a text file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
wickitom
Posts: 1
Joined: 17 Nov 2011 16:07

need help writing a simple batch file to read a text file

#1 Post by wickitom » 17 Nov 2011 16:23

I have a text file that has over a 1000 lines. I need a batch script that will read each line and after it reads "Reactions" or "reactions" it will read each line look for lines that start with "!" if a the line starts with the symbol go to next line, if the line is empty go to next line, if the line is neither, it will look at the line and see if there is the letter "o" in it. If the letter "o" is there it will put a "!" or anything I want in the beginning of that line, then skip to the next line. Here is an example of some lines

! N2 ASSUMED = AR
CH2(S)+M = CH2+M 9.000E+12 0.00 6.000E+02
H2O/0.0/ CO/0.0/ CO2/0.0/ AR/0.0/
CH2(S)+H2O = CH2+H2O 3.000E+13 0.00 0.000E+00
H2O/0.0/ CO/0.0/ CO2/0.0/ AR/0.0/

first line has "!" it would skip that line
second line has no "o" so it would skip that line
now here is the tricky part, the third line has to be skipped as well don't know how that would be written, even though this line has "o" in it
the 4th line would have to have a "!" put in front of it
the 5th line would need to have a "!" put in front of it since the 5th line is part of the 4th line
this line searching would end when the line has "end" in it

These are reaction mechanisms could be 1000's of lines, I can send someone a txt file too look at if someone wants to or you can download a file here
http://www.princeton.edu/mae/people/fac ... e/chem.inp
the file can be saved as a text file
and no I don't go to Princeton U.


Can anyone help, this type of script writing or programming is out of my league. I am sure some professionals out there or even students this might take a short time. I don't even know where to start.

aGerman
Expert
Posts: 4736
Joined: 22 Jan 2010 18:01
Location: Germany

Re: need help writing a simple batch file to read a text fil

#2 Post by aGerman » 18 Nov 2011 11:55

wickitom wrote: now here is the tricky part, the third line has to be skipped as well don't know how that would be written, even though this line has "o" in it

How should a batch file guess that?


wickitom wrote:the 5th line would need to have a "!" put in front of it since the 5th line is part of the 4th line

No. The 5th line is the 5th line. A batch code is no human. How should it know that it belongs to the 4th line?


wickitom wrote: this line searching would end when the line has "end" in it

... like in line
!ARENDS ET AL. J PHYS CHEM 97: 7914 1993
or in line
!!!!!!!!!!!!!!! PRESSURE DEPENDANCE !!!!!!!!!!!!!!!!!


wickitom wrote:I don't even know where to start.

I know it. You have to clearly define each rule and each exception. If you're unable to define these rules ... a batch file will not guess them.

Regards
aGerman

Post Reply