![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Reading text files using powershell Hi all. I have a particular problem. I have some log files that I want to search. I would like to use powershell to read the files and find a particular word. e.g. search for the word error in the log and tell me how many times it finds the word and report back. any help much appreciated. |
My System Specs![]() |
| | #2 (permalink) | ||||||||||||
| Guest | Re: Reading text files using powershell "marzy" <marzy@xxxxxx> wrote in message news:A203B368-A62A-4DEB-A08D-F8F1A2130321@xxxxxx
Get-ChildItem *.log -r | Get-Content | Foreach { $regex.Matches($_) } | measure-object -- Keith | ||||||||||||
My System Specs![]() | |||||||||||||
| | #3 (permalink) |
| Guest | Re: Reading text files using powershell If you want a count per log file report here are a couple of ways of doing it in v1.0 and v2.0 CTP $word = 'Error' # v1.0 Get-ChildItem *.log | Where-Object {Select-String "\b$word\b" $_.fullname -quiet} | Select-Object FullName, @{name = 'Count'; expression = {@((Get-Content $_.fullname | Out-String).split() -match "\b$word\b").count}} | Format-Table -auto # faster Get-ChildItem *.log | Where-Object {Select-String "\b$word\b" $_.fullname -quiet} | Select-Object FullName, @{name = 'Count'; expression = {@([regex]::matches((Get-Content $_.fullname), "\b$word\b", 1)).count}} | Format-Table -auto # one-liner versions ls *.log|?{Select-String "\b$word\b" $_.fullname -q}|select FullName,@{n='Count';e={@((gc $_.fullname|out-string).split()-match"\b$word\b").count}}|ft -a # faster ls *.log|?{Select-String "\b$word\b" $_.fullname -q}|select FullName,@{n='Count';e={@([regex]::matches((gc $_.fullname),"\b$word\b",1)).count}}|ft -a ### v2.0 CTP ### Get-ChildItem *.log | Where-Object {Select-String "\b$word\b" $_.fullname -quiet} | Select-Object FullName, @{name = 'Count'; expression = {@((gc $_.fullname | Out-String) -split ' ' -match "\b$word\b").count}} | Format-Table -auto # fastest Get-ChildItem *.log | Where-Object {Select-String "\b$word\b" $_.fullname -quiet} | Select-Object FullName, @{name = 'Count'; expression = {Select-String "\b$word\b" $_.fullname -all | ForEach-Object {$total = 0} {$total += $_.matches.count} {$total}}} | Format-Table -auto # one-liner versions ls *.log|?{Select-String "\b$word\b" $_.fullname -q}|select FullName,@{n='Count';e={@((gc $_.fullname|Out-String)-split' '-match"\b$word\b").count}}|ft -a # fastest ls *.log|?{Select-String "\b$word\b" $_.fullname -q}|select FullName,@{n='Count';e={Select-String "\b$word\b" $_.fullname -all|%{$total=0}{$total+=$_.matches.count}{$total}}}|ft -a -- Kiron |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Reading text file and charting them via powergadget | IT Staff | PowerShell | 2 | 03-19-2008 08:18 AM |
| Searching for content in text files with powershell | snofire | PowerShell | 5 | 12-31-2007 08:55 PM |
| Text reading software.. | ellisfaith | Vista General | 6 | 11-13-2007 09:24 AM |
| Reading event log files - PowerShell and LogParser 2.2 | Rob Campbell | PowerShell | 0 | 04-11-2007 03:14 PM |
| Reading the BOM of text files | Maximilian Hänel | PowerShell | 5 | 10-16-2006 02:50 PM |