Лучший отвечающий
Нераспознанная es c-последовательность

Вопрос
-
В папке находятся файлы log. в данных файлах я пытаюсь найти нужные мне значения,Но после запуска в дебагере вижу ошибку:
выполняется разбор "C:\log\1\core_2016_08_08_22_34_50.log:3070:2016-08-08 23:05:34.946 Ver 11 [R: 174] [DB2] Action en
ds in 2ms" - Нераспознанная esc-последовательность \l.
C:\script1.ps1:18 знак:27
+ if ($StringMatch | Where {!($Find -match "$_")}) {out-file -filepath ...
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException
$Files = Get-ChildItem C:\log\1\* -Include *.log $content = Get-Content $Files New-Item -ItemType file -Path C:\log\result.txt –Force $Find = "Http ->" foreach ($File in $Files) { $StringMatch = $null $StringMatch = select-string $File -pattern "[Exception]" if ($StringMatch | Where {!($Find -match "$_")}) {out-file -filepath C:\log\result.txt -inputobject $StringMatch } else {Write-Host 'error'} }
- Изменено UnkindU 27 октября 2016 г. 6:07
27 октября 2016 г. 5:50
Ответы
-
У вас ошибка в патерне. Лучше использовать такой:
"\[(Exception)|(304 Not Modified)\]"
Так же вы по идее никогда не увидите "error"
The opinion expressed by me is not an official position of Microsoft
- Изменено Vector BCOModerator 27 октября 2016 г. 6:01
- Помечено в качестве ответа KazunEditor 7 ноября 2016 г. 5:50
27 октября 2016 г. 5:56Модератор
Все ответы
-
У вас ошибка в патерне. Лучше использовать такой:
"\[(Exception)|(304 Not Modified)\]"
Так же вы по идее никогда не увидите "error"
The opinion expressed by me is not an official position of Microsoft
- Изменено Vector BCOModerator 27 октября 2016 г. 6:01
- Помечено в качестве ответа KazunEditor 7 ноября 2016 г. 5:50
27 октября 2016 г. 5:56Модератор -
У вас ошибка в патерне. Лучше использовать такой:
"\[(Exception)|(304 Not Modified)\]"
Так же вы по идее никогда не увидите "error"
The opinion expressed by me is not an official position of Microsoft
Ошибка другая.
Подозреваю,что нужно сначала экранировать спец.символы а потом искать?- Изменено UnkindU 27 октября 2016 г. 6:11
27 октября 2016 г. 6:08 -
1.
$Find = "Http -\>"
2
$StringMatch | Where {!($_ -match $find)} |out-file -filepath C:\log\result.txt -inputobject $StringMatch }
- Изменено Vector BCOModerator 27 октября 2016 г. 7:08
27 октября 2016 г. 7:04Модератор -
$Files = Get-ChildItem C:\log\1\* -Include *.log $content = Get-Content $Files New-Item -ItemType file -Path C:\log\result.txt –Force $Find = "Http -\>" foreach ($File in $Files) { $StringMatch = $null $StringMatch = select-string $File -pattern "\[Exception]" if ($StringMatch | Where {($Find -match "$_")}) {out-file -filepath C:\log\result.txt -inputobject $StringMatch } else {Write-Host 'error'} }
ошибка:
выполняется разбор "C:\log\1\core_2016_08_09_13_58_38.log:20829:2016-08-09 17:37:29.026 War 93 [R:6594] [Exception][Ty
pe:ApiException][Err:3000][HTTPStatus:NotFound][Message:PCNDLS_NoISEAccount. ISE Account not found for license: 6094][C
orrId:2cf45d91289b42d6ab4a2d773cf1d149]" - Нераспознанная esc-последовательность \l.
C:\script1.ps1:17 знак:27
+ if ($StringMatch | Where {($Find -match "$_")}) {out-file -filepath ...
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException
error27 октября 2016 г. 7:07 -
1.
$Find = "Http -\>"
2
$StringMatch | Where {!($_ -match $find)} |out-file -filepath C:\log\result.txt -inputobject $StringMatch }
$Files = Get-ChildItem C:\log\1\* -Include *.log New-Item -ItemType file -Path C:\log\result.txt –Force $Find = "Http -\>" foreach ($File in $Files) { $StringMatch = $null $StringMatch = select-string $File -pattern "\[Exception]" <#if ($StringMatch | Where {($Find -match "$_")}) {out-file -filepath C:\log\result.txt -inputobject $StringMatch } if ($StringMatch | Where {($_ -match $Find)}) {out-file -filepath C:\log\result.txt -inputobject $StringMatch } else {Write-Host 'error'}#> $StringMatch | Where {($_ -match $Find)} |out-file -filepath C:\log\result.txt -inputobject $StringMatch }
хотя искомое значение в логах есть и[Exception]
27 октября 2016 г. 8:01 -
Приложили бы файл для примера и что надо получить.
"Http -\>" - тоже надо экранировать, дожно быть "Http\ -\\>"
PS > "Http -\>" -match "Http -\>" False PS > "Http -\>" -match "Http\ -\\>" True
И лучше использовать:$_.Line
if ($StringMatch | Where {$_.Line -match $Find})
- Изменено KazunEditor 27 октября 2016 г. 10:44
27 октября 2016 г. 10:27Отвечающий -
$StringMatch | Where {!($_ -match $Find)} #|out-file -filepath C:\log\result.txt -append
вы потеряли ! + я завтыкал убрать -inputobject $StringMatch
The opinion expressed by me is not an official position of Microsoft
- Изменено Vector BCOModerator 27 октября 2016 г. 11:03
27 октября 2016 г. 10:57Модератор -
Приложили бы файл для примера и что надо получить.
"Http -\>" - тоже надо экранировать, дожно быть "Http\ -\\>"
PS > "Http -\>" -match "Http -\>" False PS > "Http -\>" -match "Http\ -\\>" True
И лучше использовать:$_.Line
if ($StringMatch | Where {$_.Line -match $Find})
"Http ->"
The opinion expressed by me is not an official position of Microsoft
27 октября 2016 г. 11:17Модератор