回答編集履歴
2
コメント欄での質問に対応して追記
answer
CHANGED
@@ -11,4 +11,28 @@
|
|
11
11
|
ch_upd_user_nm=company_B
|
12
12
|
ch_upd_user_nm=company_HOGE
|
13
13
|
PS>
|
14
|
-
```
|
14
|
+
```
|
15
|
+
|
16
|
+
---
|
17
|
+
**本回答コメント欄でいただいた[2021/09/16 13:19]の質問コメントに対応:**
|
18
|
+
|
19
|
+
> 実際のlogでは
|
20
|
+
> DEBUG ** <<1>> ** ch_upd_user_nm=company_A ~, ~,~,
|
21
|
+
> というように続いており
|
22
|
+
> 一つ目のカンマの前「ch_upd_user_nm=company_A ~」までを表示できるとベターなのですが、この場合正規表現どうなりますか。。
|
23
|
+
|
24
|
+
であれば、「','ではない文字が0個以上」、と言ったところでしょうか。`-Pattern`オプションへの指定値としては`"ch_upd_user_nm=.*company[^,]*"`です。
|
25
|
+
|
26
|
+
```PowerShell
|
27
|
+
PS> Get-Content test.log
|
28
|
+
DEBUG ** <<1>> ** ch_upd_user_nm=company_A,item2,item3
|
29
|
+
DEBUG ** <<1>> ** ch_upd_user_nm=company_B,item2
|
30
|
+
DEBUG ** <<1>> ** ch_upd_user_nm=company_HOGE
|
31
|
+
|
32
|
+
PS> Select-String -Path .\test.log -Pattern "ch_upd_user_nm=.*company[^,]*" | ForEach-Object {$_.Matches} | ForEach-Object {$_.Value}
|
33
|
+
ch_upd_user_nm=company_A
|
34
|
+
ch_upd_user_nm=company_B
|
35
|
+
ch_upd_user_nm=company_HOGE
|
36
|
+
PS>
|
37
|
+
```
|
38
|
+
※本当に適切な正規表現はご自身で調べ、考えてみてください。本回答は「パターンにマッチした部分のみを出力させる」ことが主旨のものです。
|
1
誤記修正
answer
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
何となく指定のパターン`"ch_upd_user_nm=*company*"`もやりたいことを反映してないような気がしますが、どうでしょう。少しだけ修正し、「"company"の前後
|
1
|
+
何となく指定のパターン`"ch_upd_user_nm=*company*"`もやりたいことを反映してないような気がしますが、どうでしょう。少しだけ修正し、「"company"の前後は0個以上の文字」をパターンとして、パターンにマッチした値(Value)を出力する例です。
|
2
2
|
|
3
3
|
```PowerShell
|
4
4
|
PS>Get-Content test.log
|