I need to extract a line from a text file and write that line to a new text
file. I want to do this for each line that contains the string "AB". Does
anyone know how to do this? Thanks, Rich

Re: How to extract line from text file by DiGiTAL

DiGiTAL
Tue Nov 08 10:16:28 CST 2005

Option Explicit
Dim oFSO, sFile1, sFile2, oFile1, oFile2, sText
Set oFSO = CreateObject("Scripting.FileSystemObject")
sFile1 = "c:\file1.txt"
sFile2 = "c:\file2.txt"
Set oFile1 = oFSO.OpenTextFile(sFile1, 1)
Set oFile2 = oFSO.OpenTextFile(sFile2, 8)
Do While Not oFile.AtEndOfStream
sText = Trim(ofile.ReadLine)
If InStr(sText, "AB") <> 0 Then
oFile2.WriteLine sText
End If
Loop

This will copy the line from the first file to the second file, but only
if the line contains the EXACT string of "AB". Ab, aB, or ab will not
be searched for.

Hope this helps,
DS

---
Life is all about ass; you're either covering it, laughing it off,
kicking it, kissing it, busting it, trying to get a piece of it,
behaving like one, or living with one!

*** Sent via Developersdex http://www.developersdex.com ***

Re: How to extract line from text file by ESP

ESP
Tue Nov 08 10:43:07 CST 2005

A simple LCase on both sides (the query and compare) would allow it to pick
all the variants ;-)

ESP



"DiGiTAL SKReAM" wrote:

> Option Explicit
> Dim oFSO, sFile1, sFile2, oFile1, oFile2, sText
> Set oFSO = CreateObject("Scripting.FileSystemObject")
> sFile1 = "c:\file1.txt"
> sFile2 = "c:\file2.txt"
> Set oFile1 = oFSO.OpenTextFile(sFile1, 1)
> Set oFile2 = oFSO.OpenTextFile(sFile2, 8)
> Do While Not oFile.AtEndOfStream
> sText = Trim(ofile.ReadLine)
> If InStr(sText, "AB") <> 0 Then
> oFile2.WriteLine sText
> End If
> Loop
>
> This will copy the line from the first file to the second file, but only
> if the line contains the EXACT string of "AB". Ab, aB, or ab will not
> be searched for.
>
> Hope this helps,
> DS
>
> ---
> Life is all about ass; you're either covering it, laughing it off,
> kicking it, kissing it, busting it, trying to get a piece of it,
> behaving like one, or living with one!
>
> *** Sent via Developersdex http://www.developersdex.com ***
>

Re: How to extract line from text file by richard

richard
Tue Nov 08 11:19:49 CST 2005

Cheers, this works like a charm!


ESP wrote:
> A simple LCase on both sides (the query and compare) would allow it to pick
> all the variants ;-)
>
> ESP
>
>
>
> "DiGiTAL SKReAM" wrote:
>
> > Option Explicit
> > Dim oFSO, sFile1, sFile2, oFile1, oFile2, sText
> > Set oFSO = CreateObject("Scripting.FileSystemObject")
> > sFile1 = "c:\file1.txt"
> > sFile2 = "c:\file2.txt"
> > Set oFile1 = oFSO.OpenTextFile(sFile1, 1)
> > Set oFile2 = oFSO.OpenTextFile(sFile2, 8)
> > Do While Not oFile.AtEndOfStream
> > sText = Trim(ofile.ReadLine)
> > If InStr(sText, "AB") <> 0 Then
> > oFile2.WriteLine sText
> > End If
> > Loop
> >
> > This will copy the line from the first file to the second file, but only
> > if the line contains the EXACT string of "AB". Ab, aB, or ab will not
> > be searched for.
> >
> > Hope this helps,
> > DS
> >
> > ---
> > Life is all about ass; you're either covering it, laughing it off,
> > kicking it, kissing it, busting it, trying to get a piece of it,
> > behaving like one, or living with one!
> >
> > *** Sent via Developersdex http://www.developersdex.com ***
> >