Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Reading a File, outputting contents to different file depending on exclusion Criteria.

$
0
0

Hello Everyone,

I have a pretty basic question. I have a text file that contains a lot of values. I want to parse out certain values and leave the rest.

This is the code I'm currently using, and it works, but the problem is, that instead of just ignoring lines that match the criteria, it's adding Blank lines to the new file for those lines that match the critera, The simple solution would be to parse out empty lines, but I actually need the correct new lines in the output.

 $temp = "C:\ErrorTool\ETestShort.txt"

$temp2= "C:\ErrorTool\ETestShort_Remaining.txt"

[String[]]$OUtputStuff = @()
[String[]]$tempValue = Get-Content $temp | Select-String 'ERROR:Null' -NotMatch


foreach ($line in $tempValue)
 {
 if ($line -notmatch "0>ERROR:")
{$OUtputStuff+=$line}
 }

($OUtputStuff) | Out-File $temp2


 

The input text file is similar to so:


Error: Blah blah

Error: Blah blah

Error:Null

Error: Blah blah

Error: Blah blah

 

The expected result would be:

Error: Blah blah

Error: Blah blah

Error: Blah blah

Error: Blah blah


The actual result is :

 

Error: Blah blah

Error: Blah blah

(Extra Empty line here)

Error: Blah blah

Error: Blah blah

 

 

Any ideas what I'm doing wrong?

 

 

 

 

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles