2016-07-16 5 views
1

ログファイルからいくつかのエラーを別のファイルに抽出しています。出力ファイルを上書きしますか?

私が探しているエラーは、小さなブロックで定義されています。

#Define all the error types that we need to search on 
$error_6="Missing coded entry in table for provider sector category record" 
$error_7="not a well-formed email address" 
$error_8="Org Id must not contain invalid characters" 
$error_9="Missing sub type code for provider type category record" 
$error_10="Provider sub type" 

次に、ソースログファイルを読み込み、一致する行を削除します。

別のファイルにそれらをダンプすると、各ファイルに正しい行数が得られますが、同じファイルを使用すると1行しか得られません。私はそれがファイルに追加されると思った。

(出力の唯一の1行)は動作しません

(Get-Content $path\temp_report.log) | Where-Object { $_ -match $error_6 } | Set-Content $path\known_errors.log 
(Get-Content $path\temp_report.log) | Where-Object { $_ -match $error_7 } | Set-Content $path\known_errors.log 
(Get-Content $path\temp_report.log) | Where-Object { $_ -match $error_8 } | Set-Content $path\known_errors.log 
(Get-Content $path\temp_report.log) | Where-Object { $_ -match $error_9 } | Set-Content $path\known_errors.log 
(Get-Content $path\temp_report.log) | Where-Object { $_ -match $error_10 } | Set-Content $path\known_errors.log 

作品(合計出力の16行)

(Get-Content $path\temp_report.log) | Where-Object { $_ -match $error_6 } | Set-Content $path\known_errors_6.log 
(Get-Content $path\temp_report.log) | Where-Object { $_ -match $error_7 } | Set-Content $path\known_errors_7.log 
(Get-Content $path\temp_report.log) | Where-Object { $_ -match $error_8 } | Set-Content $path\known_errors_8.log 
(Get-Content $path\temp_report.log) | Where-Object { $_ -match $error_9 } | Set-Content $path\known_errors_9.log 
(Get-Content $path\temp_report.log) | Where-Object { $_ -match $error_10 } | Set-Content $path\known_errors_10.log 
+0

あなたが変更することによって、あなたの[前の質問]への「一致」の答えを「一致しない」ことを実現します(http://stackoverflow.com/q/ 38405279/1630171)もこれに対応していますか? –

答えて

2

Set-Content常には、新しいファイルを作成します。

https://technet.microsoft.com/en-us/library/hh849828.aspx

セット内容
は、書き込みや新しいコンテンツでアイテムの内容を置き換えます。

既存のファイルにデータを追加するには、Add-Contentを使用する必要があります。

https://technet.microsoft.com/en-us/library/hh849859.aspx

アドオンコンテンツを
そのようなファイルに単語 を追加するなど、指定した項目に内容を追加します。

1

またはあなたが使用することができます。

 (Get-Content $path\temp_report.log) | Where-Object { $_ -match $error_6 } | out-file $path\known_errors.log -Append 
関連する問題