I have a file full of lines like this. There are always the same amount of semicolons and there is always a 3 character string before the first semicolon.
RT2;SS1234567;INV RED;13.06.2021;14.06.2021;154;Out;
RT2;XX1234567;INV RED;04.05.2021;14.06.2021;1472;Out;
RT2;FF1234567;INV RED;04.05.2021;14.06.2021;1472;Out;
RT2;LL1234567;INV RED;13.05.2021;14.06.2021;1472;Out;
I want to remove the beginning 3 character string and the semicolon from each row.
This is how I'm pulling in the file, it's full of blank lines and rows I need to remove
#import the file removing the first row and removing blank rows
$inFile = Get-Content -Path ($InFileDir + $InFileName)|Select-Object -Skip 1|? {$_.trim() -ne "" }
# Removes the (12334 rows affected) line that's added by sql
$inFile = $inFile|Where-Object {$_ -notlike '(*)'}
# Source file is two different sql table exports appended to each other, store the different headers
$header1 = 'RT1;Polref;Tranaction;Eff Dte;Process Dte;Fund;Movement;'
$header2 = 'RT3;Polref;Tranaction;Eff Dte;Process Dte;Fund;Qty;Amt;'
#Get some file positions
$RowBeforeheader2Index = $InFile.IndexOf($header2) -1
$header1Index = $InFile.IndexOf($header1)
$header2Index = $InFile.IndexOf($header2)
$LastRow = $inFile.Length -1
$outFile[$header1Index..$RowBeforeheader2Index]
foreach ($row in $outFile)
{
//perform a substring on the row and add to $var
}
$var|Out-file 'C:\temp\output.txt'
I'm not sure how to fill out the foreach loop to achieve my desired result. (I'm just calling it $var for for this example...I'm not that unimaginative)
EDIT:
I ended up changing $var to a list and used the following code in the foreach loop
$var = New-Object System.Collections.Generic.List[System.Object]
foreach($row in $outFile)
{
$var.Add($row.Substring(4))
}