Read and report from logfiles

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 14 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
stevelomax
Posts: 6
Last visit: Mon Dec 07, 2009 7:02 am

Read and report from logfiles

Post by stevelomax »

I'm trying to script reading from a ton (over 2,000) logfiles for a particular line and if found, report this somehow (create a txt file etc) with the computername (found in name of logfile). No need to report if it isn't found. All files are in the same folder. I'm still learning scripting and am looking for ideas or anything that could be helpful.Thanks!
User avatar
rasimmer
Posts: 182
Last visit: Fri Apr 25, 2014 7:00 am

Read and report from logfiles

Post by rasimmer »

Hey, that's cheating...how dare you use a pre-compiled EXE... :oP
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Read and report from logfiles

Post by jvierra »

First rule of scripting/administration - KISS!

Always look at the builtin OS utilities first. This will save many hundreds of wasted hours and errors.

If you just want to learn xcripting then this is not the best problem to start with.

Start with:
1. How to enumerate files in script.
2. How to read a file in script.
3. How to scan inside a string for a string.


The issues of detecting a computer name inside a line are complex and might be able to be done with ReGex. This can only be determined if the poster can describe the rules of the file structures. From the given information nothing can be easily decided.

jvierra2009-12-07 12:40:34
User avatar
stevelomax
Posts: 6
Last visit: Mon Dec 07, 2009 7:02 am

Read and report from logfiles

Post by stevelomax »

I can accomplish the tasks you describe in a script, I just need help creating the output and adding to it as it opens each successive file...still a bit over my head.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Read and report from logfiles

Post by jvierra »

Use command redirectors as with an commandline program.

YOu can filter output with this one

Code: Select all

	
FINDSTR  [/E] [/L] [/R] [/S]  [/X] [/V] [/N] [/M] [/O]  [/F:file]
        [/C:string] [/G:file] [/D:dir list] [/A:color attributes] [/OFF[LINE]]
        strings [[drive:][path]filename[ ...]]
	
  /B         Matches pattern if at the beginning of a line.
  /E         Matches pattern if at the end of a line.
  /L         Uses search strings literally.
  /R         Uses search strings as regular expressions.
  /S         Searches for matching files in the current directory and all
             subdirectories.
  /I         Specifies that the search is not to be case-sensitive.
  /X         Prints lines that match exactly.
  /V         Prints only lines that do not contain a match.
  /N         Prints the line number before each line that matches.
  /M         Prints only the filename if a file contains a match.
  /O         Prints character offset before each matching line.
  /P         Skip files with non-printable characters.
  /OFF[LINE] Do not skip files with offline attribute set.
  /A:attr    Specifies color attribute with two hex digits. See "color /?"
  /F:file    Reads file list from the specified file(/ stands for console).
  /C:string  Uses specified string as a literal search string.
  /G:file    Gets search strings from the specified file(/ stands for console).
	

Run findstr against the piped ouput or file created with redirected output.

If you qould raather try with scripting then start by using the Scripting.FileSystemObject to enumerate teh files and then use ReadLine or ReadAll to reads teh files.

User avatar
stevelomax
Posts: 6
Last visit: Mon Dec 07, 2009 7:02 am

Read and report from logfiles

Post by stevelomax »

for this it does...sometimes I guess we all overcomplicate things...thanks for the help!
This topic is 14 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked