Wednesday, February 27, 2019

Read a File 1 Line at a Time

$file = "FILE NAME GOES HERE"
$line = Get-Content $file | Select -First 1
$line.Substring(0, 50)
$line.Length


<# Get-Content $file | Select -First 10 | ForEach-Object { $_ } #>

$count = 0
$stream = New-Object System.IO.StreamReader($file)
Write-Output("CL_PA_ID|CL_SYS_ID")
while (($line = $stream.ReadLine()) -ne $null -and $count -lt 100)
        {
            $CL_SYS_ID = $line.Substring(30, 1)
            if ($CL_SYS_ID -eq "K" -or $CL_SYS_ID -eq "L") {
                $out = $line.Substring(14, 9) + "|" + $line.Substring(30, 1)
                Write-Output($out)
                $count = $count + 1
            }
        }
$stream.Close();

No comments:

Post a Comment