Reputation: 3996
I have a strange and bit complicated issue with csv file. CSV file contain 10K+ records. It contains a list of the application version.
Canon MF Toolbox 4.9.1.1.mf09 Canon MF Toolbox 4.9.1.1.mf11
Canon MF Toolbox 4.9.1.1.mf12 Canon MF Toolbox 4.9.1.1.mf14 Canon MF Toolbox 4.9.1.1.mf15 Canon MF Toolbox 4.9.1.1.mf16 Canon MF Toolbox 4.9.1.1.mf17 Canon MF Toolbox 4.9.1.1.mf18
I need to get the data before numeric value. So, my output would contain Canon MF Toolbox.
This is just an example there is much software. I can open and read the csv from PowerShell but I am not sure how to get the result which I am looking for.
Import-Csv c:\scripts\software.csv |`
ForEach-Object {
$Name += $_.Name
write-host $name;
}
Any advice.
Upvotes: 0
Views: 58
Reputation: 44285
You can add a regex that excludes numbers to your ForEach-Object iterator.
$Name = "Canon MF Toolbox 4.9.1.1.mf09 Canon MF Toolbox 4.9.1.1.mf11"
[regex]::Match($Name, "[A-Za-z_\s]*").captures.groups[0].value
Returns
Canon MF Toolbox
If you need to modify the regex as you discover new patterns in your data I recommend regex101.com
Upvotes: 1