The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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-21-2008 01:14 AM
Need Replacement for sed dbsurf Shell Programming and Scripting 0 01-25-2008 06:47 PM
Regarding Replacement rajx UNIX for Dummies Questions & Answers 2 05-22-2007 09:19 AM
Replacement using sed handak9 UNIX for Dummies Questions & Answers 5 07-13-2004 11:28 AM
cpu replacement. help IMPTRUE UNIX for Dummies Questions & Answers 3 07-25-2003 08:40 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-28-2001
Babu Babu is offline
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
  #2 (permalink)  
Old 06-30-2001
kapilv kapilv is offline
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 (permalink)  
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:02 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0