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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
problem with tr command ravi raj kumar UNIX for Advanced & Expert Users 2 07-02-2007 07:41 AM
problem with mv command dsravan Shell Programming and Scripting 7 06-07-2007 12:32 PM
where is the problem in my sed command.... P_W UNIX for Dummies Questions & Answers 5 04-20-2007 10:48 PM
problem with dd command or maybe AFS problem Anta Shell Programming and Scripting 0 08-25-2006 11:10 AM
ls command problem buckhtr77 SUN Solaris 2 12-06-2005 04:16 PM

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 09-04-2008
tsaravanan tsaravanan is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 13
problem in sed command

Hi,

i have a script to replace a string.

$ cat List.txt
/DIR1/DIR2/DIR3/abcdefgh
/DIR1/DIR2/DIR3/abcd
/DIR1/DIR2/DIR3/abcdefghijk
/DIR1/DIR2/DIR3/xyz

$ ind=`/DIR1/DIR2/DIR3/abcd`
$ replace=`#/DIR1/DIR2/DIR3/abcd`
$ sed "s|$find|$replace|g" List.txt>cat NewList.txt

The aim of above 3 lines are to modify the line /DIR1/DIR2/DIR3/abcd as #/DIR1/DIR2/DIR3/abcd.
but the its replacing the 3 lines as bellow

$ cat NewList.txt
#/DIR1/DIR2/DIR3/abcd
#/DIR1/DIR2/DIR3/abcdefgh
#/DIR1/DIR2/DIR3/abcdefghijk
/DIR1/DIR2/DIR3/xyz

i has to replace only one line.

help me in solving this problem.

Thanks in advance.

~Saravana..
  #2 (permalink)  
Old 09-04-2008
agn agn is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 172
A slight modification to your sed expression should do this.


Code:
$ sed "s|$find$|$replace|g" List.txt>cat NewList.txt

  #3 (permalink)  
Old 09-04-2008
tsaravanan tsaravanan is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 13
thanks yar. its working fine.
  #4 (permalink)  
Old 09-04-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,342
Backticks is used to set the result of a command to a variable not to assign a value to a variable, use quotes instead:


Code:
find="/DIR1/DIR2/DIR3/abcd"
replace="#/DIR1/DIR2/DIR3/abcd"

sed "s/$find/$replace/" List.txt > NewList.txt

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:25 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