Batch - parse .txt file

February 8, 2010 at 11:39:47
Specs: Windows XP
I have written a program in VBA that
successfully copies text from text boxes in
.pub files and saves them in a .txt file. Right
now I have ~80 text files in my directory

My goal is to convert these files to html

I am trying to write a batch file that will:
A) Parse every text file within the
aforementioned directory
B) Add a <'br'> (minus quotes)tag at every line
break. A line break in these text files is
represented as a symbol that looks like '[][]'.
I'm not sure what this is or how I would
reference it.
C) Ensure that there is only 1 space after any
period contained within the text.

Any help is greatly appreciated.

See More: Batch - parse .txt file

Report •

February 8, 2010 at 13:21:40
I suggest you choose vbscript or any script language you want but avoid batch as the "<" and ">" symbols for html tags are hated by batch scripts being interpreted as redirectors.

To workaround you are forced to set up tricky code that must be taylored for each specific case. More the presence of the misterious [][] may signal the presence of characters not in the standard side of codepage adding further complexity.

Sorry, maybe other guys/gales are more helpful.

Report •

February 8, 2010 at 22:24:05
Ivo has the right idea, avoid script. I've wrestled with these xml/html files and gets ugly fast. it can be done, but the amount of time spent is not worth it for a script file that might blow up next time you try to use in on something new.
I've been planning to write a general purpose translator in very-very-simple basic (translatable into vis.basic), so if you want a copy, I can post it up when i'm done. Or you can look for a windows version of unix TR at
Whatever else, to get the ball rolling, you need to find out what those line-break char.s really are. Use EDIT /70:
EDIT /70 file.txt
position the cursor onto the characters and see what it says in the bottom right corner of the screen, where it says:
Line: nn Col: nn Value: xx
That, Value, is what you need to report for both char.s. (it's in decimal, not hex, so 13 is car.ret, 10 is linefeed, etc).

Report •

February 9, 2010 at 05:49:02
Very helpful.

Thanks nbrane and ivo

Report •

Related Solutions

February 9, 2010 at 06:14:19
How would I write a script to replace a characters whose value
= 13?

Something like:

Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\DBText\Security
Services_JW.txt", ForReading)

strText = objFile.ReadAll
strNewText = Replace(strText, chr(13), "elephant")

Set objFile = objFSO.OpenTextFile("C:\DBText\Security
Services_JW.txt", ForWriting)
objFile.WriteLine strNewText

Is doing nothing

Report •

February 9, 2010 at 06:15:43
Actually nevermind, the above code does work.

Report •

February 9, 2010 at 07:12:37
If you still have a line break, change Chr(13) to vbNewLine.

Report •

Ask Question