|
server
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Search in text filesHi,
We have a lot of log files in txt format. How can I write a script that will search in de text file for a certain text ? So if the script found that messag (for example error ..) I can send an email or give a print-out. Thanks ! Hi,
If you were using Windows PowerShell you could do the core of what you want using the get-content cmdlet. Suppose you have a file MyLog.txt. The following would display lines on screen where "Error" occurs. get-content MyLog.txt | where-object {$_ -match "Error"} If you wanted to save error lines to a text file use this: $a = get-content MyLog.txt | where-object {$_ -match "Error"} $a > ErrorLines.txt To retrieve the content of the ErrorLines.txt: get-content ErrorLines.txt Andrew Watt MVP On Tue, 16 Jan 2007 01:48:01 -0800, Bengyke <Beng***@discussions.microsoft.com> wrote: Show quoteHide quote >Hi, > >We have a lot of log files in txt format. How can I write a script that will >search in de text file for a certain text ? So if the script found that >messag (for example error ..) I can send an email or give a print-out. > >Thanks ! Const ForReading = 1
fName = "C:\scripts\log.txt" strToFind = "error" Set fso = CreateObject ("Scripting.FileSystemObject") Set file = fso.OpenTextFile (fName, ForReading, false) If Not file.AtEndOfStream Then contents = file.ReadAll Else Wscript.Echo "Log file empty" Wscript.Quit End If If InStr (contents, strToFind) > 0 Then 'actions if error message found End If -- Show quoteHide quoteurkec "Bengyke" wrote: > Hi, > > We have a lot of log files in txt format. How can I write a script that will > search in de text file for a certain text ? So if the script found that > messag (for example error ..) I can send an email or give a print-out. > > Thanks !
Write to file multiple times from Powershell
Migration from vbscript to powershell Getting group members of group on Domain A that contains users on Domain B checking for blocked inheritance in a group of users Can't log AD user in Script file for maping network drives add a local printer ADS_UF_PASSWD_NOTREQD = &h00020 Printer Port Settings Install application (new to this scripting lark) |
|||||||||||||||||||||||