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-fileThis 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