2016-07-16 6 views
1

J'extrais des erreurs d'un fichier journal dans un fichier séparé.Ecriture du fichier de sortie?

Les erreurs que je suis à la recherche d'une définition dans un petit bloc. J'ai ensuite lu dans le fichier journal source et supprimer les lignes correspondantes.

Ce qui est bizarre est que si je les stocker dans des fichiers séparés, je reçois le nombre exact de lignes dans chaque fichier, mais si j'utilise le même fichier que je ne reçois que 1 ligne. Je pensais que cela s'ajouterait au dossier.

ne fonctionne pas (seulement 1 lignes de sortie)

(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 

Works (16 lignes de production au total)

(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

Vous vous rendez compte que, en changeant les réponses à votre [question précédente] "correspond pas" à "match" (http://stackoverflow.com/q/ 38405279/1630171) travaillent pour cela aussi, n'est-ce pas? –

Répondre

1

ou vous pouvez utiliser:

 (Get-Content $path\temp_report.log) | Where-Object { $_ -match $error_6 } | out-file $path\known_errors.log -Append