If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Help in replace method

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-16-09, 11:38
SeenuGuddu SeenuGuddu is offline
Registered User
 
Join Date: Sep 2009
Posts: 16
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
Reply With Quote
  #2 (permalink)  
Old 11-16-09, 11:49
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
is this homework?
Reply With Quote
  #3 (permalink)  
Old 11-16-09, 12:02
SeenuGuddu SeenuGuddu is offline
Registered User
 
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..?
Reply With Quote
  #4 (permalink)  
Old 11-16-09, 12:05
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Why not pipe the output through another sed command similar to your first one?
Reply With Quote
  #5 (permalink)  
Old 11-16-09, 23:54
SeenuGuddu SeenuGuddu is offline
Registered User
 
Join Date: Sep 2009
Posts: 16
Thanks Mike .. Got it
Reply With Quote
  #6 (permalink)  
Old 11-17-09, 10:30
SeenuGuddu SeenuGuddu is offline
Registered User
 
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
Reply With Quote
  #7 (permalink)  
Old 11-17-09, 11:04
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
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?
Reply With Quote
  #8 (permalink)  
Old 11-20-09, 01:48
SeenuGuddu SeenuGuddu is offline
Registered User
 
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...
Reply With Quote
  #9 (permalink)  
Old 11-20-09, 04:13
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On