LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Replace a field in quotes within a csv file (http://www.linuxquestions.org/questions/programming-9/replace-a-field-in-quotes-within-a-csv-file-947295/)

hattori.hanzo 05-28-2012 09:42 PM

Replace a field in quotes within a csv file
 
I have a csv file which contains 1 field that has quotes. The content in that field changes all the time but is always in double quotes. ie "blah"

I could like to replace that field with 123 or just blank.

Code:

abc,"def",ghi
How do I go about this. Tried sed find replace but since the content within the quotes changes, I probably need to use a delimiter or marker?

Thanks.

danielbmartin 05-28-2012 09:53 PM

Try this:
Code:

echo 'abc,"def",ghi' | sed 's/".*"/123/'
Daniel B. Martin

grail 05-29-2012 01:21 AM

You didn't indicate whether or not you need to keep the quotes around the new value?

catkin 05-29-2012 02:10 AM

Quote:

Originally Posted by grail (Post 4689940)
You didn't indicate whether or not you need to keep the quotes around the new value?

.. or whether the quoted strings include double quotes, perhaps by adjacent double quotes ("") or backslash escaping (\").


All times are GMT -5. The time now is 04:27 PM.