I'm trying to clean a file and make it pipe or tilde delimited
the file has text qualifiers sporadically throughout
like:
jim,jones,"123 Main St",Detroit,MI
connie,hill,"1234 Front St","St Marie, Detwa",WI
I would like to strip all the quotes and replace the delimiters without interfering with commas within fields.
If your data is in fact CSV, then the easiest way would probably be the following:
$data = Import-Csv csvdata.txt # -Header Name,LastName,Street,City,State # if no headers are there
$data | %{ ($_.Name,$_.LastName,$_.Street,$_.City,$_.State) -join '|' } | Out-File new.txt
This leverages PowerShell's native CSV import to build a list of objects with properties. You can then manually create the lines again with your own delimiter (necessary since Export-CSV will quote every field, always).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.