Scripting the editing of a log/text file

155 pts.
Tags:
DOS
Log files
Scripting
VB
Visual Basic
I am looking to remove complete lines of text from a log file. Would prefer to do this in a batch file if possible and also to use wildcards in the searching for the line to remove. i.e. find the text within a file matching "the content of this file stating * to be removed" (where the asterisk is "anything" variable). Once found, that line and the line above it would be deleted. Was starting out using the EDIT Dos command but cannot find and relevant information on the sytax of the command to go any further than opening the document. May have to resort to VB but this is not my forte. Thanks
ASKED: June 24, 2009  4:55 PM
UPDATED: June 25, 2009  6:36 PM

Answer Wiki

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

From a Windows command script you can do several things to parse text. The most complicated is to use a FOR loop to parse it one line at a time, use a sub routine for parsing and ECHO the result back out to a new file.

The simplest solution is to use FINDSTR with the “/v” option which prints out lines that do not match and redirect to a new file.

If you have a large number of criteria to test against, I suggest using a FINDSTR for each criteria or use the “/G” option to feed a file with the search criteria.

There are several methods of specifying the search criteria.

Example of basic findstr command using the “/C” search string option:

findstr /v /i /c:”My criteria” “C:\temp\test.txt”>”C:\temp\test2.txt”

Tools that can be used as a filter or editing tool:
FINDSTR, FIND, SED, GREP, AWK

For SED, the SSED port as Windows 32-bit application is a great tool
I don’t have a specific AWK windows port to recommend
The Microsoft port of GREP works well (resource kit tool)

Personally, I prefer FINDSTR to FIND for manipulating text files.

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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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

Following