EOF

  • Thread starter Thread starter Gordy
  • Start date Start date
G

Gordy

Is it possible to write a script that searches an ASCII
file for a unique string and then places an EOF character
immediately after this string or deletes all text that
follows it?
 
Gordy said:
Is it possible to write a script that searches an ASCII
file for a unique string and then places an EOF character
immediately after this string or deletes all text that
follows it?

Yes, of course! :-)
 
I don't even know where to start. Could you help?
-----Original Message-----


Yes, of course! :-)

--
Phil Robyn
Univ. of California, Berkeley

u n z i p m y a d d r e s s t o s e n d e - m a i l

.
 
In said:
Is it possible to write a script that searches an ASCII
file for a unique string and then places an EOF character
immediately after this string or deletes all text that
follows it?

Which do you want to do? What OS and what tools are to be used (batch,
VBS, 3rd-party utilities)? If you truncate the file do you still need
an EOF? If you insert a 026(dec) what application do you expect to
stop reading at that point? What is the actual problem you are trying
to solve?
 
Every day we are FTP'ed a file from our corporate office
that we combine with a second file generated at this
location to produce a log file.

Unfortunately, we only want the top half of the ASCII file
that we are FTP'ed. The file always contains the
string "<end>" to distinguish the top (wanted) half from
the bottom (unwanted) half.

Batch or WSH/VBScript would be fine but a Word macro is
not an option.
 
Gordy said:
Is it possible to write a script that searches an ASCII
file for a unique string and then places an EOF character
immediately after this string or deletes all text that
follows it?

Hi

If the text file is large, the following vbscript will take a while:


Const OpenAsASCII = 0 ' Opens the file as ASCII (TristateFalse)
Const OpenAsUnicode = -1 ' Opens the file as Unicode (TristateTrue)
Const OpenAsDefault = -2 ' Opens the file using the system default

Const OverwriteIfExist = -1
Const FailIfNotExist = 0
Const ForReading = 1

' path to original log file
sOrgFile = "C:\logs\test_org.txt"

' path to new log file
sNewFile = "C:\logs\test_new.txt"
' if you want to overwrite the original file, use the line below instead
'sNewFile = sOrgFile

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set fOrgFile = oFSO.OpenTextFile(sOrgFile, ForReading, _
FailIfNotExist, OpenAsASCII)

sText = fOrgFile.ReadAll
fOrgFile.Close

iPos = InStr(1, sText, "<end>", vbTextCompare)

If iPos > 0 Then
' <end> is found at position iPos
' get all text before (a.k.a. over) <end>, including <end>
sText = Left(sText, iPos + 4)

Set fNewFile = oFSO.CreateTextFile(sNewFile, _
OverwriteIfExist, OpenAsASCII)

fNewFile.WriteLine sText
fNewFile.Close
End If
 
Gordy said:
Every day we are FTP'ed a file from our corporate office
that we combine with a second file generated at this
location to produce a log file.

Unfortunately, we only want the top half of the ASCII file
that we are FTP'ed. The file always contains the
string "<end>" to distinguish the top (wanted) half from
the bottom (unwanted) half.

So is the string "<end>" on a line all by itself, or is it
at the end of a line, or in the middle of a line, or at
the beginning of a line?
 
Unfortunately, it can be either and all. I thought this
fact in itself would be the biggest obstacle.
 
Magic - thanks Torgeir!
-----Original Message-----


Hi

If the text file is large, the following vbscript will take a while:


Const OpenAsASCII = 0 ' Opens the file as ASCII (TristateFalse)
Const OpenAsUnicode = -1 ' Opens the file as Unicode (TristateTrue)
Const OpenAsDefault = -2 ' Opens the file using the system default

Const OverwriteIfExist = -1
Const FailIfNotExist = 0
Const ForReading = 1

' path to original log file
sOrgFile = "C:\logs\test_org.txt"

' path to new log file
sNewFile = "C:\logs\test_new.txt"
' if you want to overwrite the original file, use the line below instead
'sNewFile = sOrgFile

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set fOrgFile = oFSO.OpenTextFile(sOrgFile, ForReading, _
FailIfNotExist, OpenAsASCII)

sText = fOrgFile.ReadAll
fOrgFile.Close

iPos = InStr(1, sText, "<end>", vbTextCompare)

If iPos > 0 Then
' <end> is found at position iPos
' get all text before (a.k.a. over) <end>, including
 
Back
Top