Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2003
    Posts
    9

    Unanswered: how to replace pattern of string stored in a variable

    I would like to replace say abc[d]192[d] to abc-192-, ie. replacing [d] with -. The value of abc[d]192[d] is stored in a variable say "myvar".

    ie. myvar = "abc[d]192[d]"

    I am using csh. I want this to be done inside script, not replacing those characters for external file(s).

    I have seen this before, but can't remember how to do it.

    hope someone can help.

    thanks

  2. #2
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    138
    try this :
    myvar="abc[d]123[d]"
    newvar=`echo $myvar | sed s/"\[d\]"/-/g`
    echo $newvar
    Greetings from germany
    Peter F.

  3. #3
    Join Date
    Sep 2003
    Posts
    9
    thanks it works even though i thought that there is another way.

    thanks again

Posting Permissions

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