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 > 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 and shell scripting languages 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 07:14 AM
Replacing Last occurance of & from a string vivekshady Shell Programming and Scripting 1 05-13-2008 08:15 PM
Replacing string in files mohan705 Shell Programming and Scripting 2 08-29-2007 01:27 AM
Problem replacing the string Viken Shell Programming and Scripting 2 03-18-2007 06:38 PM
string replacing priya_9patil Shell Programming and Scripting 1 11-03-2006 12:05 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-29-2008
ragavhere ragavhere is offline
Registered User
  
 

Join Date: Apr 2008
Location: Chennai,India
Posts: 79
Unhappy problem in replacing a string

Hi,

I have a file with the path of the directory present somewhere in it.I have assigned the path of the directory name to a variable. I want to replace it with another string.The code i used was

sed -e '/$variable/sbcd/' filename.

since the path name includes slashes '/', my sed command is not working. How to solve this out to replace the path name with another string.
  #2 (permalink)  
Old 04-29-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
change the ' to " and use a different separator - not / plus you need an s:
Code:
sed -e "s#$variable#sbcd#" filename
  #3 (permalink)  
Old 04-29-2008
ragavhere ragavhere is offline
Registered User
  
 

Join Date: Apr 2008
Location: Chennai,India
Posts: 79
Thumbs up problem in replacing a string

Wow. Thats great. Thanks a lot.
  #4 (permalink)  
Old 05-02-2008
ragavhere ragavhere is offline
Registered User
  
 

Join Date: Apr 2008
Location: Chennai,India
Posts: 79
Lightbulb problem in replacing a string

Hi,

How do i replace one variable with another variable?

for e.g
inp1=ab
inp2=cd

how do i replace $inp1 with $inp2?

And how do i replace a string with a variable?

Can you please help?I am stuck here.
  #5 (permalink)  
Old 05-02-2008
DILEEP410 DILEEP410 is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 148
Post

Quote:
Originally Posted by ragavhere View Post
Hi,

How do i replace one variable with another variable?

for e.g
inp1=ab
inp2=cd

how do i replace $inp1 with $inp2?

And how do i replace a string with a variable?

Can you please help?I am stuck here.
Can you please make the question more clear ?
  #6 (permalink)  
Old 05-02-2008
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
Quote:
Originally Posted by ragavhere View Post
Hi,

How do i replace one variable with another variable?

for e.g
inp1=ab
inp2=cd

how do i replace $inp1 with $inp2?

And how do i replace a string with a variable?

Can you please help?I am stuck here.
What you like to do?
as i got your question it is a easy task to do

just do
Code:
$inp1=$inp2  or $inp2=$inp1
or elaborate more on the question part.
  #7 (permalink)  
Old 05-02-2008
Vicky Narayan Vicky Narayan is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 21
Buddy,

As my friend Dileep has correctly pointed out, your question seems to be confusing.
As per my understanding,
"how do i replace $inp1 with $inp2?" means u want to swap the values of the two variables, is it?
If yes then use one more variable and u can easily swap the values stored in the variables.
Replacing a string with a variable means you want to assign a variable to another variable rather then assigning it to some string,rite?
If so den u can do it d same way as u do for string. But here the variable needs to have some value stored in it.
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 12:38 PM.


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