Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing comma's within quatation marks

Status
Not open for further replies.

masalachol

Technical User
Apr 8, 2004
20
US
Hello:

I am bringing this up again since we have gotten a little further and my previous comments and thus looking for some urgent input.

Well I have a csv file where some strings are enclosed by a quotation marks. We found that the following sed operation sed 's/\(".*\)[,]\(.*"\)/\1\2/g'
will remove the comma's within the quotation marks (if any exist)(this is what we want) only if one set of quotation marks exist within each line. When more than one set of quotation marks exists then the sed operation does not work on that particular line.

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

xxxxxxx,xxxxxxxx,"Russellville,",AR,xxxxxx,xxxxxxx,xxxxxxxx,",ARLINGTON HEIGHTS,IL,60005,US,5.96,0.98,,,,,,,,,,,,,,,,,,,,, ,,,,

Therefore, does any one know how to pass a second or third or multiple arguments within the sed operations so when it does pass through a line with multiple quotes it understands it and executes the operation of removing the comma's which is what we want to accomplish.
 
I think the problem is your regex is greedy.
Instead of: .* use: [^"]*
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top