Reputation: 1467
On a windows host I am looking through log files for specific failures.
The string I am looking for is SERV_, but I don't want SERV_SUCCESS or SERV_FAIL. For example, SERV_REPLACE is one of several codes I want to catch.
grep SERV *.log -d -n | grep -v SERV_SUCCESS *.log -d -n
does not work (returns all lines - everthing matches), but it doesn't complain about syntax either.
All of my topic searches are giving solutions that apply to Linux systems.
Upvotes: 1
Views: 426
Reputation: 58451
Following terse syntax would look recursively
.log
filesSERV_
SERV_FAIL
or SERV_SUCCESS
gci *.log -rec -file | sls 'SERV_' | sls -NotMatch 'SERV_(FAIL|SUCCESS)'
A more readable version would be
Get-ChildItem *.log -Recursive -File |
Select-String 'SERV_' |
Select-String -NotMatch 'SERV_(FAIL|SUCCESS)'
Upvotes: 0
Reputation: 13834
If you use Powershell, you can use Select-String
to achieve what you are looking for. Here is the reference for it.
The Select-String cmdlet searches for text and text patterns in input strings and files. You can use Select-String similar to grep in UNIX or findstr.exe in Windows.
Select-String
[-Pattern] <string[]>
[-Path] <string[]>
[-SimpleMatch]
[-CaseSensitive]
[-Quiet][-List]
[-Include <string[]>]
[-Exclude <string[]>]
[-NotMatch]
[-AllMatches]
[-Encoding <Encoding>][-Context <int[]>]
[<CommonParameters>]
Get-Command | Out-File -FilePath .\Command.txt
Select-String -Path .\Command.txt -Pattern 'Get', 'Set' -NotMatch
Upvotes: 1