Help in replace method


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help in replace method
# 1  
Old 11-16-2009
Help in replace method

Hi Gurus,

VARIABLE=john_*_has_*_s

i want to replace the * with digits 09100 and 0010101

to print the john_09100_has_0010101_s

Thanks
# 2  
Old 11-16-2009
Code:
VARIABLE='john_*_has_*_s'

bash/ksh:
Code:
VARIABLE='john_*_has_*_s'
VARIABLE=${VARIABLE/\*/09100}
VARIABLE=${VARIABLE/\*/0010101}
echo $VARIABLE

sed:
Code:
echo $VARIABLE|sed 's/\*/09100/;s/\*/0010101/'

awk:
Code:
echo $VARIABLE|awk -F\* '{print $1 "09100" $2 "0010101" $3}'

# 3  
Old 11-17-2009
Thanks .. for it

echo john_*_has_*_s | sed 's/*/10101/' | sed 's/*/789/'
# 4  
Old 11-17-2009
Quote:
Originally Posted by SeenuGuddu
Thanks .. for it

echo john_*_has_*_s | sed 's/*/10101/' | sed 's/*/789/'
Hi SeenuGudu,

Good, though using
Code:
echo john_*_has_*_s | sed 's/*/10101/;s/*/789/'

-or-
Code:
echo john_*_has_*_s | sed -e 's/*/10101/' -e 's/*/789/'

is more efficient, because it saves a pipe ('|'). The variable expansion that I mentioned earlier, may look cumbersome, but in fact it is even more efficient because it saves another pipe plus the calling of an external program (sed)

S.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Another method for this snippet

Hi All, i believe this is not very efficient. another method would be appreciated for these. basically i read a file with tab delimited column and pass the column to another perl script. while read line do timestamp=`echo "$line"|awk -F"\t" '{print $1}'` severity=`echo... (15 Replies)
Discussion started by: ryandegreat25
15 Replies

2. Shell Programming and Scripting

How to replace a text containing new lines using sed or any other method?

Hi, i want to replace "Hi How are You when did you go to delhi" to "Hi How are you when did you come from delhi" in a file. Any idea how to do it? (2 Replies)
Discussion started by: abhitanshu
2 Replies

3. Shell Programming and Scripting

Cleaner method for this if-then statement?

I have a script that runs once per month. It performs a certain task ONLY if the month is January, April, July, or October. MONTH=`date +%m` if || || || ; then do something else do a different thing fi Is there a neater way of doing it than my four separate "or" comparisons? That... (2 Replies)
Discussion started by: lupin..the..3rd
2 Replies

4. Solaris

svc:/network/physical:default: Method "/lib/svc/method/net-physical" failed with exit status 96. [ n

After a memory upgrade all network interfaces are misconfigued. How do i resolve this issue. Below are some out puts.thanks. ifconfig: plumb: SIOCLIFADDIF: eg000g0:2: no such interface # ifconfig eg1000g0:2 plumb ifconfig: plumb: SIOCLIFADDIF: eg1000g0:2: no such interface # ifconfig... (2 Replies)
Discussion started by: andersonedouard
2 Replies

5. Programming

message and method

Differentiate between the message and method. (2 Replies)
Discussion started by: robinglow
2 Replies

6. Solaris

How to get the status of the method

Hi, I have created a services and method to start the processes. Method: #!/sbin/sh . /lib/svc/share/smf_include.sh case "$1" in 'start') /usr/local/proce start sleep 10 ;; 'stop') /usr/local/proce stop ;; *) echo... (5 Replies)
Discussion started by: kalpeer
5 Replies

7. Programming

Regarding Native method

Hi, I am working with solaris 9 and I am using jre1.6. In my application,I am using java and C++ in my application.Basically we are using the java for front end and C/C++ for back hand.So I have to call the C/C++ source code form java code.we are using native methods for it.. So application... (1 Reply)
Discussion started by: smartgupta
1 Replies

8. UNIX for Dummies Questions & Answers

Optimized Method

Hi All, I have got two files. File A with 50000 records and File B with some 500 million records. I need to extract the mapping data (common data) from both the files. There should be definitely many ways :) though I have a way which is definitely not optimzed and takes a longer time... (2 Replies)
Discussion started by: matrixmadhan
2 Replies

9. Shell Programming and Scripting

which encryption method?

hello ppl, i've been coding a perl script for xchat and i need to store the nick's passwords. i was wondering which encryption to use. picture this situation: i've got a system flaw and some guy hacks the machine and gets his hands on the passwd file; he has access to the script. what encryption... (2 Replies)
Discussion started by: crashnburn
2 Replies

10. UNIX for Advanced & Expert Users

Backup method

Hi I'm trying to work out the best method for creating a backup under SCO OpenServer. I would like to perform unattended backups to tape of various file systems, possibly using a script etc. So far I've looked at the Backup Manager that comes with SCO and that cannot perform unattended... (2 Replies)
Discussion started by: synamics
2 Replies
Login or Register to Ask a Question