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

Output Full Lines in a Text File to a New File

$
0
0

I am trying to read a source file, then output only lines that start with a specific string to a new file. The issue that I am having is that the lines are long (1000+ chars) and the outputted lines are wrapping. Each full line in the source file needs to be the same full (unbroken) line in the target file.

$data = get-content "C:\TEST\INBOUND\DATA\TEST_IMP.TXT"

foreach($line in $data)
{
    if($line.length > 2){

        if($line.substring(0,2) -eq "AZ" )
        { 
            write-host $line | out-file -filepath "C:\TEST\INBOUND\DATA\TEST_OUT."
        }
    }    
}

Any help would be MUCH appreciated.


Viewing all articles
Browse latest Browse all 6937

Trending Articles