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"
panyam
June 16, 2009, 6:04am
5
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
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"
an easy way is
sed 's/\(.*\),\(.*\)/\1\2/g'
panyam
June 16, 2009, 6:16am
7
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
panyam:
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
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
panyam:
good work .. Ahmed bhai
Thanks man but my name is Ahmad Diab not Ahmad bhai
BR