Scripting the editing of a log/text file
155 pts.
0
Q:
Scripting the editing of a log/text file
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: Jun 24 2009  4:55 PM GMT
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
0
1095 pts.
0
A:
 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0
  • AddThis Social Bookmark Button
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.
Last Answered: Jun 25 2009  6:36 PM GMT by Pjb0222   1095 pts.
0
0
Discuss This Answer:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _



_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Troy Tate   0 pts.  |   Jun 25 2009  4:44PM GMT

Check out the script I mentioned in the discussion on this previous question. Basically it is a rewrite of an existing logfile to a new logfile.

In the IT trenches? So am I - read my IT-Trenches blog

 
0