powershell - Remove New Line Character from CSV file's string column -
i have csv file string column column spans multiple lines. want aggregate multiple lines 1 line.
for example
1, "asdsdsdsds", "john" 2, "dfdhifdkinf dfjdfgkdnjgknkdjgndkng dkfdkjfnjdnf", "roy" 3, "dfjfdkgjfgn", "rahul" i want output be
1, "asdsdsdsds", "john" 2, "dfdhifdkinf dfjdfgkdnjgknkdjgndkng dkfdkjfnjdnf", "roy" 3, "dfjfdkgjfgn", "rahul" i want achieve output using powershell
thanks.
try this:
$csv = 'c:\path\to\your.csv' (import-csv $csv -header 'id','value','name') | % { $_.value = $_.value -replace "`r`n",' ' $_ } | export-csv $csv -notypeinformation if csv contains headers, remove -header 'id','value','name' import , replace value actual column name.
if don't want double quotes around fields, can remove them replacing export-csv this:
... | convertto-csv -notypeinformation | % { $_ -replace '"' } | out-file $csv to remove header output add filter before out-file skip first line:
... | select -skip 1 | out-file $csv
Comments
Post a Comment