I would to remove only the fifth comma in a CSV file and remove all additional space.
i.e. Original file A,B100537 ,8438,TRUST ,VECCO 4 PORT USB 2.0 MINI HUB ,BLACK ,0000000000000009.01,14591
result A,B100537 ,8438,TRUST COMPUTER ,VECCO 4 PORT USB 2.0 MINI HUB BLACK ,0000000000000009.01,14591
Code:
$x = Get-Content file.txt
$x | Foreach-Object {$_.Trim() -replace '^([^,]*,[^,]*,[^,]*,[^,]*,[^,]*),(.*)$', '$1 $2' -replace '\s+', ' ' } | Set-Content output.txt