Read and report from logfiles
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.
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.
- stevelomax
- Posts: 6
- Last visit: Mon Dec 07, 2009 7:02 am
Read and report from logfiles
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!
Read and report from logfiles
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
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
- stevelomax
- Posts: 6
- Last visit: Mon Dec 07, 2009 7:02 am
Read and report from logfiles
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.
Read and report from logfiles
Use command redirectors as with an commandline program.
YOu can filter output with this one
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.
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.
- stevelomax
- Posts: 6
- Last visit: Mon Dec 07, 2009 7:02 am
Read and report from logfiles
for this it does...sometimes I guess we all overcomplicate things...thanks for the help!