Find and Replace Path in UNIX | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Find and Replace Path in UNIX

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 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 01-04-2013
Scrutinizer's Avatar
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 29 July 2014, 1:11 AM EDT
Location: Amsterdam
Posts: 9,281
Thanks: 260
Thanked 2,303 Times in 2,066 Posts
Why is that not useful, what result do you get?
Sponsored Links
    #3  
Old 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 01-04-2013
RudiC RudiC is online now Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 31 July 2014, 7:28 AM EDT
Location: Aachen, Germany
Posts: 3,939
Thanks: 63
Thanked 936 Times in 888 Posts
Strange, your command works perfectly for me...
Sponsored Links
    #5  
Old 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 01-04-2013
RudiC RudiC is online now Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 31 July 2014, 7:28 AM EDT
Location: Aachen, Germany
Posts: 3,939
Thanks: 63
Thanked 936 Times in 888 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 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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 07:28 AM.