Thread: sed programming Help need..

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    22

    sed programming Help need..

    Hi All,
    i need to write a script using sed programming to replace a character into string.I mean i have a file with comma(,) seperated and optionally enclosed(").Now the problem is some of field having (") in between string.
    example -
    "WAIVED/CES "GOOD","WAIVED BASED ON CES & "A" PB","WAIVED BASED ON PB & "A" PAID"

    Now i want to write a sed script to replace in between " from field.I mean if there is " in between a field it should replace by space.

    Pls help me to sort out the above problem.I m nt much aware in sed prog.


    Thanks n advance.
    Anwar

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Code:
    $ sed 's/"\([^",]*\),,*\([^",]*\)"/"\1\2"/g'
    "hello, world",123,zog
    "hello world",123,zog
    "hello",world,123,zog
    "hello",world,123,zog
    "hello,,,,,",world,123,zog
    "hello",world,123,zog
    ",world",123
    "world",123
    123,456
    123,456
    
    The blue lines are the responses to typing in various lines (in black)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    22
    Actually my requirement is bit different.
    Suppose -
    "WAIVED/CES "GOOD","WAIVED BASED ON CES & "A" PB","WAIVED BASED ON PB & "A" PAID"

    so i want output like
    "WAIVED/CES GOOD","WAIVED BASED ON CES & A PB","WAIVED BASED ON PB & A PAID"

    i mean all extra quote wil replace by space or (~ char ) also fine for me. I mean

    "WAIVED/CES ~GOOD","WAIVED BASED ON CES & ~A~ PB","WAIVED BASED ON PB & ~A ~PAID"

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    OK, I've shown you how, now you have a go.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Parsing a string like I would with grep and sed
    By Motark in forum C Programming
    Replies: 8
    Last Post: 11-13-2008, 12:10 PM
  2. Sed and the nth-occurence flag.
    By indigo0086 in forum Linux Programming
    Replies: 1
    Last Post: 07-19-2007, 09:09 PM
  3. xml file parsing in C
    By lonbgeach in forum Tech Board
    Replies: 31
    Last Post: 12-14-2006, 02:14 AM
  4. using SED
    By xErath in forum Tech Board
    Replies: 1
    Last Post: 10-04-2005, 09:36 PM
  5. problem in using a library (libpci.a)
    By jeanyves in forum C Programming
    Replies: 2
    Last Post: 06-17-2004, 08:36 AM