Hi I would like to use awk
or sed
to remove blanks spaces before a comma in a CSV file.
Example input file would be:
"abcd" ,"test 123"
Output file:
"abcd","test 123"
Only remove white space before a comma but not in between words. looking for trim function in unix. Please help. Thank you very much.
This can be easily done with sed:
sed 's/ *,/,/' csv-file
This tells sed to remove sequences of whitespace characters (of any length) before commas.
Notes:
The assumption here is that commas are illegal within the fields (i.e "test, 123" is illegal).
As you requested, this removes whitespaces only before commas. if you want to remove whitespaces which are after commas as well:
sed 's/ *, */,/' csv-file
This should work:
cp file1 file2
perl -pi -e 's/" ,"/","/g' file2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With