Quoting the values in second field

Hi,

I have got a file comp_data containing the below data :

38232836|9302392|49
39203827|8203203,3933203|52
72832788|567,3245,2434324|100

This file can have many rows like shown above. I want the values separated by "," in second column(taking "|" as delimiter) to be in quotes. These values can be of any length
Output should be:

38232836|'9302392'|49
39203827|'8203203','3933203'|52
72832788|'567','3245','2434324'|100

The comma separated second column can have any number of values. I want all values to be in quotes. Please help me.

awk -F\| 'BEGIN{OFS=FS} {gsub(/,/,q","q,$2);sub(/^/,q,$2);sub(/$/,q,$2)}1' q=\' infile
1 Like

Thanks a lot :slight_smile: