Results 1 to 6 of 6

Thread: sed/awk

  1. #1
    Join Date
    Apr 2007
    Posts
    21

    Unanswered: sed/awk

    i have file containing lines such as

    Char(Month(L.prd_cvrg_end_dt)) =
    STRIP(substr(V_MON_YR,1,2),L,'0')
    AND Char(Year(L.prd_cvrg_end_dt))

    which i need to change as:

    Char(Month(L.prd_cvrg_end_dt)) =
    STRIP(substr(V_MON_YR,1,2),'L','0')
    AND Char(Year(L.prd_cvrg_end_dt))

    how do i get this done.

    i.e. change only the character ,L, to ,'L',

    i attempted using sed/awk it looks like i have an error.
    Last edited by usc; 05-09-07 at 20:51.

  2. #2
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    Code:
    cat in-file | sed -e 's/,L,/,'L',/g' > out-file
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

  3. #3
    Join Date
    Apr 2007
    Posts
    21
    the single quote didn't make the changes.

    tried double quote(") instead of single quote('), it works

    cat t1 | sed -e "s/,L,/,'L',/g" > t2
    Last edited by usc; 05-10-07 at 13:54.

  4. #4
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    yeah single quote will cause an error
    i.e.
    cat in-file | sed -e 's/,L,/,'
    then L
    then ',/g' > out-file

    I'm not 100% on sed but i would imagine you could delimit that to give you :
    cat in-file | sed -e 's/,L,/,\'L\',/g' > out-file

  5. #5
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    Right. Escaping the nested single quotes will work. This is not an sed thing but rather the shell takes care of the escaping.
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

  6. #6
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    Quote Originally Posted by usc
    the single quote didn't make the changes.

    tried double quote(") instead of single quote('), it works

    cat t1 | sed -e "s/,L,/,'L',/g" > t2
    ...and why exactly do you need a 'cat'?
    vlad
    +-----------------------+
    | #include <disclaimer.h> |
    +-----------------------+

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •