Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

search and delete from text file

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I need a script that will search a text file and delete any lines that dont start with a 1. Is this possible or should I say practical?
 
nfisuq2,
Your request is both possible and practical. View the following link to the MSDN VBScript documentation. This particular link describes the FileSystemObject.


About half-way down the page is an example of reading data from a file.

Somewhere after reading a line, check the first leftmost character to see if it's a 1.
.
.
.
' Read the contents of the file.
Response.Write &quot;Reading file <br>&quot;
Set ts = fso_OpenTextFile(&quot;c:\testfile.txt&quot;, ForReading)
s = ts.ReadLine
' Add code to check string contents here:
If (Left(s, 1) = 1) Then
Response.Write &quot;File contents = '&quot; & s & &quot;'&quot;
End If
ts.Close
.
.
.

What's next is up to you. Are you going to write the info to a new file? Are you going to overwrite the existing file?

Zy
 
Then read one line in at a time from the source file and if it starts with 1, write it to the destination file, otherwise get the next line, etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top