WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Arrays
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Remove a Line from a File Using Arrays

 Keywords: Remove Delete Skip Line File Array Keyword Matching Text ArrayRemove ArrayLocate StrIndex StrIndexNC ArrayFileGet ArrayFilePut

Question:

How can I remove a line from a file that contains a keyword?

Answer:

ignorekeyword = 'hello' ; Case Insensitive

inputfilename = "c:\temp\test.txt"
outputfilename = "c:\temp\testout.txt"

inputarray = ArrayFileGet (inputfilename , "" , 0)
linecount = ArrInfo(inputarray,6) -1

For index = 0 To linecount
 line = inputarray[index]
 position = StrIndexNC( line, ignorekeyword, 1, @FWDSCAN ) ; Skip lines where keyword is found
 If position != 0
    ; Remove line/element from the array
    ArrayRemove( inputarray, index )
    index = index-1
    linecount = linecount-1
 EndIf
Next
ArrayFilePut(outputfilename, inputarray)
Pause( "", "Done" )
Exit

Article ID:   W17665
Filename:   Remove a Line from a File Using Arrays.txt
File Created: 2012:10:24:10:29:16
Last Updated: 2012:10:24:10:29:16