I'm trying to import and process a CSV. From the position 2-4 of the third column, I want to write that line to a file with that identifier.
As an example, from line 1 for "results.csv" I am trying to write to a file named "274.txt" the matching line:
10.121.8.84,TRUE,N274SECX9010C5D,3/20/2015 15:48
I am somewhat certain my regex maybe wrong. It looks fine and is able to go through sample text in Expresso. However, when added to script, I do not see any results.
Results.csv:
10.121.88.84,TRUE,N274SECX9610C5D,3/20/2015 15:48
10.77.89.109,TRUE,L186OFFX2K6KMX1,3/24/2015 9:49
10.144.18.135,TRUE,N488FOOD2NK6MB1,3/25/2015 7:20
10.181.92.175,FALSE,,
10.147.86.54,FALSE,,
Powershell Code:
$path = Split-Path -parent $MyInvocation.MyCommand.Definition
$Results_File = $path + "\results.csv"
Import-Csv $Results_File | ForEach {
If ($_ -Match '^.*,\w(?<filename>\d{3}).*') {
$_ | Out-File -Append "$($Matches.Filename).csv"
}
}
.*s and end up with:,\w(?<filename>\d{3}).