Hi everyone,
I'm new to PowerShell. I'm trying to read a text file, find matching pattern ("NO RECORD") and replace it with ("NORECORD") then output the result to a new CSV file. However I didn't get the result I wanted
This is what I've done so far
Data file: sample_data.txt
DATE AF QD QU
09/30/1920 NO RECORD 370.00 NO RECORD
10/01/1920 NO RECORD 391.00 391.00
10/02/1920 NO RECORD 496.00 MISSING
10/03/1920 NO RECORD 660.00 MISSING
10/04/1920 NO RECORD 881.00 MISSING
10/05/1920 NO RECORD 660.00 MISSING
10/06/1920 NO RECORD 515.00 -9999
10/07/1920 NO RECORD 443.00 NO RECORD
10/08/1920 NO RECORD 443.00 MISSING
10/09/1920 NO RECORD 443.00 443.00
10/10/1920 NO RECORD 443.00 MISSING
Code:
$infile = "sample_data.txt"
$outfile = "test.csv"
Get-Content $infile | % {$_ -replace 'NO RECORD','NORECORD'} | Export-Csv -Path $outfile -NoTypeInformation
Output: in Excel
Length |
40 |
50 |
49 |
49 |
49 |
49 |
49 |
47 |
50 |
49 |
48 |
48 |
Any suggestion would be appreciated. Thanks!