The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
replacing string in an XML file subin_bala Shell Programming and Scripting 2 06-03-2008 04:14 AM
Replacing Last occurance of & from a string vivekshady Shell Programming and Scripting 1 05-13-2008 05:15 PM
problem in replacing a string ragavhere Shell Programming and Scripting 9 05-02-2008 06:02 AM
Replacing string in files mohan705 Shell Programming and Scripting 2 08-28-2007 10:27 PM
string replacing priya_9patil Shell Programming and Scripting 1 11-03-2006 09:05 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-18-2007
Registered User
 

Join Date: Mar 2007
Posts: 4
Problem replacing the string

I have three files that the string inside it I want to replace
so my code will be

#!/bin/bash
read -p "please input the old string:" string1
read -p "please input the new string:" string2
sed -i "s/string1/string2/g" *.c

but the problem is.. the string that I want to replace can't be changed
is that possible the code that i wrote is wrong ?
there is have any solution ?

thank you
Reply With Quote
Forum Sponsor
  #2  
Old 03-18-2007
Registered User
 

Join Date: Sep 2006
Posts: 1,580
string1 and string2 are variables. when you call variables, put $. something like this
eg
Code:
sed -i "s/$string1/$string2/g" *.c
Reply With Quote
  #3  
Old 03-18-2007
Registered User
 

Join Date: Mar 2007
Posts: 4
Thank you very much
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 03:28 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