Param( $filename = 'c:\Temporary\Import1.csv', $newFile = 'c:\Temporary\Import2.csv' ) $content = Get-Content $filename $outRecords = @() foreach( $record in $content ) { $array = $record.Split( ',' ) ## entries in $array are zero-based if ($array.Length -lt 101) { $outRecords += $record } else { if ($array[3] -eq '65-ABCDEF' ) { if ($array[99] -eq "") { if ($array[98].Length -gt 5) { $array[99] = $array[98].substring($array[98].length-6,5) } } } $outRecords += $array -join "," } } $outRecords | Out-File $newFile -Encoding ASCII
Select allOpen in new window
Param( $filename = 'c:\Temporary\Import1.csv', $newFile = 'c:\Temporary\Import2.csv' ) $content = Get-Content $filename $outRecords = @() foreach ($record in $content) { $array = $record.Split(',') ## entries in $array are zero-based if ($array.Length -lt 101) { $outRecords += $record } else { if ($array[3] -eq '65-ABCDEF' ) { if (($array[99] -eq "") -and ($array[98].Length -gt 5)) { $array[99] = $array[98].Substring($array[98].length-6, 5) } if ($array[99] -match '\d{5}$')) { $array[100] = $Matches[0] } } $outRecords += $array -join "," } } $outRecords | Out-File $newFile -Encoding ASCII
Open in new window