The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


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 !!

More UNIX and Linux Forum Topics You Might Find Helpful
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

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-28-2001
Registered User
 

Join Date: Jun 2001
Location: India
Posts: 3
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  
Old 06-30-2001
Registered User
 

Join Date: Nov 2000
Location: India
Posts: 83
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  
Old 07-04-2001
ajg ajg is offline
Registered User
 

Join Date: Jul 2001
Location: Belfast
Posts: 4
You could try using 'sed'...
To replace 'bob' with whatever's in the variable $jim, do:

#/bin/sh
jim=&lt;some-calculation&gt;
cat <filename> | sed "s/bob/$jim/g"

It's a lot nicer...

NB: If $jim contains '/' characters, do this instead:

cat &lt;filename&gt; | 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
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 08:09 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0