Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Find and Replace Path in UNIX

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-04-2013
nsyed.dw nsyed.dw is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 4 January 2013, 7:03 AM EST
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Linux Find and Replace Path in UNIX

Hi All,

How can i find and replace the one path to another path with in the file.

For Example:


Code:
Search_path=/search/path
replace_path=/replace/path

I used the following command but not usefull, please help me regarding the same.


Code:
sed 's_/search/path_/replace/path_' file_name > tmp_file.txt


Last edited by Scrutinizer; 01-04-2013 at 03:19 AM.. Reason: code tags
Sponsored Links
    #2  
Old Unix and Linux 01-04-2013
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 29 August 2016, 11:03 PM EDT
Location: Amsterdam
Posts: 10,987
Thanks: 427
Thanked 3,037 Times in 2,699 Posts
Why is that not useful, what result do you get?
Sponsored Links
    #3  
Old Unix and Linux 01-04-2013
nsyed.dw nsyed.dw is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 4 January 2013, 7:03 AM EST
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
I am getting following error...

sed: command garbled:

Search_path=/search/path_old

replace_path=/replace/path_new

Last edited by nsyed.dw; 01-04-2013 at 04:21 AM..
    #4  
Old Unix and Linux 01-04-2013
RudiC RudiC is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 30 August 2016, 1:04 PM EDT
Location: Aachen, Germany
Posts: 9,269
Thanks: 181
Thanked 2,704 Times in 2,531 Posts
Strange, your command works perfectly for me...
Sponsored Links
    #5  
Old Unix and Linux 01-04-2013
nsyed.dw nsyed.dw is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 4 January 2013, 7:03 AM EST
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Syntax:

sed 's_/search/path_old_/replace/path_new/_' ttt.txt > tmp.txt

Error:

sed: command garbled: s_/search/path_old_/replace/path_new/_

Above systax is not working for me, please help me.

---------- Post updated at 04:30 AM ---------- Previous update was at 04:25 AM ----------

Please any once can help me....
Sponsored Links
    #6  
Old Unix and Linux 01-04-2013
RudiC RudiC is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 30 August 2016, 1:04 PM EDT
Location: Aachen, Germany
Posts: 9,269
Thanks: 181
Thanked 2,704 Times in 2,531 Posts
Now this is clear - you did not post the offending command in post#1.
Code:
sed: command garbled: s_/search/path_old_/replace/path_new/_

cannot interpret the substitute command as your separator "_" also exists in your patterns! Replace separator by ":" and it flies.
Sponsored Links
    #7  
Old Unix and Linux 01-04-2013
nsyed.dw nsyed.dw is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 4 January 2013, 7:03 AM EST
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks alot RUDIC, its working now.
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
find and replace a path with sed? JC_1 Shell Programming and Scripting 8 08-27-2012 06:15 PM
Find, replace, file path in multiple files for Solaris 10 LRoberts Emergency UNIX and Linux Support 5 04-21-2011 09:31 AM
Find and replace string from file which contains variable and path - SH hakermania Shell Programming and Scripting 2 09-03-2010 11:50 AM
Find unix path to a file? jmarc UNIX for Dummies Questions & Answers 4 10-28-2009 11:03 AM
how to find complete path of a file in unix yahoo! UNIX for Advanced & Expert Users 1 07-25-2008 01:49 AM



All times are GMT -4. The time now is 01:13 PM.