Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Remove Field From CSV

Last post 05-16-2008, 4:39 PM by Sergei Z. 1 replies.
Sort Posts: Previous Next
  •  05-16-2008, 4:21 PM 42351

    Remove Field From CSV

    How would I write code in SED to remove the data enclosed in quotes, in a CSV file? In addition, the code must also ignore any other quotes inside the field itself.

     

     

    For example:

     

    Before: ,"Hi "Bob" how are you?", 

    After: ,,

     

     

    Fortunately Excel will tag double quotes inside a quoted field with an extra quote so I'm actually dealing with data like this:

     

    ,"Hi ""Bob"" how are you?", 

     

    However, I suspect my code is aborting the pattern match at the first quote on the left of "Bob" which leaves the entire field unmodified. The code I was trying to use is:

    s/,"[^"]*",/,,/

    How can I make it ignore the double quotes inside the field and only pick up the last ",? 

  •  05-16-2008, 4:39 PM 42352 in reply to 42351

    Re: Remove Field From CSV

    i don't do sed, but generic pattern for that task would be

    ,"("[^"]*"|[^"])+",

    i guess in sed u could try

    s/,"("[^"]*"|[^"])+",/,,/

View as RSS news feed in XML