![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Disk Replacement SVM | Actuator | SUN Solaris | 4 | 05-20-2008 10:14 PM |
| Need Replacement for sed | dbsurf | Shell Programming and Scripting | 0 | 01-25-2008 03:47 PM |
| Regarding Replacement | rajx | UNIX for Dummies Questions & Answers | 2 | 05-22-2007 06:19 AM |
| Replacement using sed | handak9 | UNIX for Dummies Questions & Answers | 5 | 07-13-2004 08:28 AM |
| cpu replacement. help | IMPTRUE | UNIX for Dummies Questions & Answers | 3 | 07-25-2003 05:40 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
global replacement
hello,
I have a problem in replacing a value with another one in a file,the actual situation is i am writing an shell script,in that i want to cat a file and that replace the values in the file with a calculated values,which is in a variable... regards babu
__________________
babu |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Hi
well this can also be done.
#!/bin/ksh #initialize the variable for e.g the variable is var1 #your calculaions go here. for var=var+1 vi fname <<! :%s/search_string/$var1/g :wq ! |
|
#3
|
|||
|
|||
|
You could try using 'sed'...
To replace 'bob' with whatever's in the variable $jim, do: #/bin/sh jim=<some-calculation> cat <filename> | sed "s/bob/$jim/g" It's a lot nicer... NB: If $jim contains '/' characters, do this instead: cat <filename> | sed "s/bob/$(echo $jim | sed 's/\//\\\//g')/g" ... ok... maybe it's not that nice Remember, double quotes are needed if a variable is to be expanded inside them. |
|||
| Google The UNIX and Linux Forums |