I have the following code:
$reader = [System.IO.File]::OpenText(".\Babytest.txt")
try {
for(;;)
{
$line = $reader.ReadLine()
if($line eq $null) {break}
if($line -notMatch 'BB1') { $line }
}
}
finally {
$reader.Close()
}
The way I understand this code, is:
$reader = [System.IO.File]::OpenText(".\Babytest.txt")
-- Opens the test.txt file
for(;;)
{
$line = $reader.ReadLine()
if($line eq $null) {break}
if($line -notMatch 'BB1') { $line }
-- If the line is null= EOF break code Else go into another IF look for all lines where there is no 'BB1' in it, output $line
What I want to do
First of all, this code works, although the IF - notmatch doesn't seem to be working, I still see the lines with BB1 in them in my output to the shell. What am I missing?
How can I write this out to a file? This is kind of more loopy stuff oppose to the pipe stuff, so I'm not sure if something like
|out-file "\\fhnsrv01\home\aborgetti\Documentation\Scripts\Baby Removal Project\babyoutput.txt"
would work...all help is greatly appreciated... I've been researching this all day, but it seems powershell has a learning curve, I'm getting the hang of it, there's just so much you can do...
UPDATE
Example String:
AR|111000111011|500001|1|DavT|2013-09-10 12:03:18|2014-04-07 10:23:09|A25415|3|2013-08-11|2013-08-13|Y|01 |APPROVED|01 |APPROVED|35 |
String with no BB1
AR|111100001BB1|500002|1||2014-04-02 15:30:12|2014-04-04 10:55:54|A32009|3|2014-03-31|2014-04-02|Y|01 |APPROVED|03 |PENDING|34 |
String with BB1
I want to remove the lines like BB1 line