Remove a specific line in text file

5 pts.
Tags:
Batch files
text files
I have a text file that has records that begin with "7". I need to delete all the lines that start with "7".
1

Answer Wiki

Thanks. We'll let you know when a new response is added.

vbscript, basic read/write code from
http://stackoverflow.com/questions/1142678/read-and-write-into-a-file-using-vbscript
cscript delete7.vbs
—- delete7.vbs —-
Set objFS = CreateObject(“Scripting.FileSystemObject”)
strFile = “fred.txt”                  ‘ your input file
strTemp = “temp.txt”
IntCount = 0
Set objFile = objFS.GetFile(strFile)
Set objOutFile = objFS.CreateTextFile(strTemp,True)
Set ts = objFile.OpenAsTextStream(1,-2)
Do Until ts.AtEndOfStream
    strLine = ts.ReadLine
    if (left(strline,1) <> “7”) then
        objOutFile.Write(strLine) & chr(13) & chr(10)
    else
        intCount = intCount + 1
    end if
Loop
wscript.echo intCount & ” lines deleted”
objOutFile.Close
ts.Close
objFS.DeleteFile(strFile)
objFS.MoveFile strTemp,strFile

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • ToddN2000
    Sounds like homework. This can be done easily using SQL. Is this an option or does it have to be a program?
    134,635 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: