Results 1 to 9 of 9
  1. #1
    Join Date
    Sep 2009
    Posts
    16

    Unanswered: Help in replace method

    Hi Gurus,

    VARIABLE=john_*_has_*_s

    i want to replace the * with digits 09100 and 0010101

    to print the echo john_09100_has_0010101_s

    Thanks

  2. #2
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    is this homework?

  3. #3
    Join Date
    Sep 2009
    Posts
    16
    no Mike i did .. but i am getting this

    echo john_*_has_*_s | sed 's/*/10101/'

    john_10101_has_*_s

    fine but the second * to replace with another id..?

  4. #4
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    Why not pipe the output through another sed command similar to your first one?

  5. #5
    Join Date
    Sep 2009
    Posts
    16
    Thanks Mike .. Got it

  6. #6
    Join Date
    Sep 2009
    Posts
    16
    Hi Mike
    echo john_*_has_*_s | sed 's/*/10101/' | sed 's/*/789/'

    if it is dynamically..?

    echo john_${var1}_has_${var2}_s

  7. #7
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    Quote Originally Posted by SeenuGuddu View Post
    Hi Mike
    echo john_*_has_*_s | sed 's/*/10101/' | sed 's/*/789/'

    if it is dynamically..?

    echo john_${var1}_has_${var2}_s
    I appreciate it has a question mark but normally questions start with words like how, what and why. I'm not at all sure what you're trying to do or why you're doing it in the first place. Would it be better to try and explain why you want to do this?

  8. #8
    Join Date
    Sep 2009
    Posts
    16
    Hi Mike this is working finee with tested values

    #!/bin/ksh

    V_DATE="2007-11-30"
    V_ID=789
    V_NAME="john_${V_ID}_has_${V_DATE}_s"

    FILE_NAME=`echo ${V_NAME}`

    echo ${FILE_NAME}

    Buttt the problem is

    the first two values will come dynamically

    and the file will looks like "john_${V_ID}_has_${V_DATE}_s*" soo i have to get the file from remote system and i have to further processs based on the
    date and ID

    "filename" i am storing it in varaible and ID and Date aswell

    But when i `echo ${FILE_NAME}` it prints

    john_${V_ID}_has_${V_DATE}_s*

    its nt replacing the values

    can u give the solution for this...

  9. #9
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    I couldn't see any major issues in your code so I entered it into my system :
    Code:
    #!/bin/ksh
    
    V_DATE="2007-11-30"
    V_ID=789
    V_NAME="john_${V_ID}_has_${V_DATE}_s"
    FILE_NAME=`echo ${V_NAME}`
    
    echo "V_DATE=$V_DATE"
    echo "V_D=$V_ID"
    echo "V_NAME=$V_NAME"
    echo "FILE_NAME=$FILE_NAME"
    
    exit
    And ran it which produced the following which looked correct :
    Code:
    V_DATE=2007-11-30
    V_D=789
    V_NAME=john_789_has_2007-11-30_s
    FILE_NAME=john_789_has_2007-11-30_s
    Can you check you're using double quotes everywhere - single quotes won't translate the variable values ie make sure you type " and not ' or '' (which is actually two single quotes typed one after the other).

    Another point is that it would be easier to read if you had FILE_NAME=$V_NAME rather than printing out V_NAME and capturing the output. Even better might be to just use one variable rather than two holding the same value.

    Also where did the * come from in FILE_NAME - I can't see how that could of been set using your code.

    Mike

Posting Permissions

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