Hi,
I am trying to replace a specific column values in a csv file with double quotes.
Example:
SNO,NAME,ZIPCODE,RANK,CARE_OF
1,Robert,74538,12,RICHARD JOHNSON, P.C
2,Sam,07564,13,% R.S MIKE, V.K.S
3,Kim, Ed,12345,14,@90 KMS, %TK
Desired Output:
SNO,NAME,ZIPCODE,RANK,CARE_OF
1,Robert Ken,74538,12,"RICHARD JOHNSON, P.C"
2,Sam Mik,"07564",13,"% R.S MIKE, V.K.S"
3,"Kim, Ed",12345,14,"@90 KMS, %TK"
I would like to replace the zipcode value with double quotes when I find a leading zeros for the zipcode. Also, I would like to replace the name in double quotes when I found a comma with in the name.
Also, I would like to replace the CARE_OF value with double quotes when I found a comma with in this column value.
The following command is working fine for Name and Zipcode column values, please advice on CARE_OF column value.
sed -e 's/,\(0[0-9]*\)/,\"\1\"/g' -e 's/,\([ 0-9A-Za-z]*, [ 0-9A-Za-z]*\),/,\"\1\",/g' -e 's/,\([ 0-9A-Za-z]*, [ 0-9A-Za-z]*\),/,\"\1\",/g' inputFile.csv > outputFile.csv
Please throw your ideas
Thanks,
moris.