Windows 환경에서 로그 파일 작업을 시도하는 Solaris 관리자. 로그 파일을 추적하려고하는데 무시하고 싶은 6 개의 반복되는 행이 있습니다. 다음과 같이 라인을 선택할 수있었습니다.
Get-Content alert.log -Tail 300 -Wait | Select-String -Pattern "WARNING: too" -Context 1,6
하지만이 '컨텍스트'줄을 무시하려고합니다. 나는 -NotMatch
끝에 추가하려고 시도했지만 결국 무시하려는 줄을 인쇄합니다.
Solaris에서는 다음을 수행합니다.
tail -300f alert.log | egrep -B1 -A6 -v "WARNING: too"
나는 성공하지 않고 PowerShell에 상응하는 것을 찾으려고합니다. 하나의 일치하는 줄을 무시하는 데 성공했습니다.
Get-Content alert.log -Tail 300 | ?{$_ -notmatch 'WARNING: too'}
그러나 이것을 위와 아래 줄로 어떻게 연장합니까? 무시하고 싶은 라인 유형은 다음과 같습니다.
2020-05-20T15:32:13.870875+10:00
WARNING: too many parse errors
PARSE ERROR:
2020-05-20T15:32:13.886503+10:00
begin ORACLE PL/SQL; end;
Additional information: hd=00007FF6E4A08E68
...Current username=FRED
...Application: work3wp.exe
조치 :이 문장을 만들 수있었습니다.
Get-Content .\alert_prod.log -Tail 300 -Wait | ?{$_ -notmatch "WARNING: too|begin FRED|Additional information|Current username|Application: work3wp.exe|PARSE ERROR:" }
그러나 오류가 시작될 때마다 날짜 / 시간 스탬프가 나타납니다. 다른 오류의 날짜 / 시간 스탬프를 원합니다.
PowerShell은 텍스트가 아닌 개체 지향 언어입니다. 문자열은 또 다른 개체입니다.
사용 사례에 따라 다음을 수행 할 수 있습니다. 물론 * nix에서 보여주는 것만 큼 직접적이지는 않지만, 물론 PowerShell은 * nix가 아니므로 PowerShell 방식으로 수행해야합니다.
그래서 이것이 제가 여러분이 고려할 수있는 것입니다. PowerShell에서 X 또는 Y 작업을 수행하는 방법은 항상 6 가지가 있습니다. 일부는 다른 것보다 더 우아합니다.
Get-Content -Path 'D:\temp\abc.txt'
<#
# Results
a=abcdef123
b=ngh567
c=defh123
#>
Get-Content -Path 'D:\temp\abc.txt' -Tail 3 -Wait |
ForEach{$PSItem -notmatch 'c'}
# After adding test to the file and saving
<#
# Results
False
True
False
True
True
#>
# After adding checking to the file and saving
<#
# Results
False
True
False
True
True
True
False
#>
Get-Content -Path 'D:\temp\abc.txt' -Tail 3 -Wait |
ForEach{Select-String -InputObject $PSItem -NotMatch 'context'}
<#
# Results
a=abcdef123
b=ngh567
c=defh123
#>
# After adding a string to the file and saving
<#
# Results
testing
#>
# After adding context to the file and saving
# no response
# after adding a new filtered string
<#
# Results
after c*text
#>
# after adding 3 lines including 1 filtered string and saving
<#
# Results
blank line before c*text
line after c*text
#>
# What's in the file now
Get-Content -Path 'D:\temp\abc.txt'
<#
# Results
a=abcdef123
b=ngh567
c=defh123
testing
context
after c*text
blank line before c*text
context
line after c*text
#>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다