Removing commas within semicolon in a flat file

Hi ,

Im relatively new to unix and have to process a comma serparated flat file . I recieve some of the fields in double quotes and i want to remove it ..

INPUT

filed1,field2,field3,"fie,ld4"

OUTPUT

field1,field2,field3,"field4"

can anyone tell me how to achieve this .

What do you want to remove, double quotes ? Your OUTPUT is not really clear on this point.

kindly use the below code:-

sed 's/\(fie\),\(ld4\)/\1\2/g'

I want to remove the commas that will come within double quotes ...

filed1, field2,field3,"fie,ld4"

i want to remove the comma in "fie,ld4" so that the output is

field1,field2,field3,"field4"

note : field name are just dummy that i am using , data can be anything in strings like

rahul,rohan,ansal,"bankofbaroda,dehi"

iwant to remove the comma in "bankofbaroda,delhi"

Assumes that only one word in the line will have double quotes

echo '"file,d1",field2,field3,field4' |  sed 's/\(.*\)"\(.*\),\(.*\)"\(.*\)/\1"\2\3"\4/'

output
"filed1",field2,field3,field4
an easy way is

sed 's/\(.*\),\(.*\)/\1\2/g'
Code:

an easy way is

sed 's/\(.*\),\(.*\)/\1\2/g'

Reply With Quote
It will work only in case of the double quoted string at the end

ahmad , panyam .. can you please explain the usage of sed 's/\(.*\),\(.*\)/\1\2/g'
in your code

Fine but this will work where the quote is found in first,middle,or at end

sed 's/\(\".*\),\(.*\"\)/\1\2/g'

this code can be used regardless of the number of fields not only 4 fields.

but there is a condition :- no double quote in the same line

good work .. Ahmed bhai :slight_smile:

Thanks man but my name is Ahmad Diab not Ahmad bhai :slight_smile:
BR