LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 07-23-2011, 12:56 AM   #1
texasj
LQ Newbie
 
Registered: Feb 2011
Posts: 23

Rep: Reputation: 2
Unhappy problem in replacing string in vi editor


I tried to replace a windows directory structure to linux directory structure in vi editor but it's giving me error "E488 trailing characters" (O.S is redhat 5)

F:\oracle\app\oradata

I want to replace it to

/u002/app/oracle

I have been searching this for 2 days & didn't get any solution.! Can any body know how to replace it?
Thanks in advance......!

Last edited by texasj; 07-23-2011 at 01:03 AM.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 07-23-2011, 01:23 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

The back slashes in the original path are special and so are the forward slashes in the replace part.

Try this:
Code:
:s%F:\\oracle\\app\\oradata%/u002/app/oracle%
Hope this helps.
 
1 members found this post helpful.
Old 07-23-2011, 01:58 AM   #3
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,971

Rep: Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849
Hello texasj,

for me with vim this works
Code:
:%s/F:\\oracle\\app\\oradata/\/u002\/app\/oracle/g
Explanation:
% search the whole file
s substitute
\\ a backslash
\/ a slash in Linux/Unix
g replace every occurence in the whole line (without g it replaces only the first one)

Markus

Last edited by markush; 07-23-2011 at 02:22 AM.
 
1 members found this post helpful.
Old 07-23-2011, 02:12 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi markush,
Quote:
Originally Posted by markush View Post
for me with vim this works.....
That doesn't seem to work...

1) You have a double backslash before the F:
2) The back-referencing doesn't replace the backslash between app and oradata (it should also be replaced by something else).

EDIT: The above code has been changed (see post #5).

Last edited by druuna; 07-23-2011 at 02:29 AM.
 
2 members found this post helpful.
Old 07-23-2011, 02:21 AM   #5
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,971

Rep: Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849
Quote:
Originally Posted by druuna View Post
Hi markush,


That doesn't seem to work...

1) You have a double backslash before the F:
2) The back-referencing doesn't replace the backslash between app and oradata (it should also be replaced by something else).
Sorry, you're right, 1) was a mistake, 2) I did not see that, I've changed the codeline in my above post.

Markus
 
1 members found this post helpful.
Old 07-23-2011, 02:30 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
@markush:

The OP now has 2 ways of solving his/her problem!
 
Old 07-23-2011, 02:36 AM   #7
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,971

Rep: Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849
Hello druuna,
Quote:
Originally Posted by druuna
The OP now has 2 ways of solving his/her problem!
yes, he has , maybe he tries some solutions with sed, awk or perl, the problem seems to be somewhat educating.

Markus
 
Old 07-26-2011, 12:00 AM   #8
texasj
LQ Newbie
 
Registered: Feb 2011
Posts: 23

Original Poster
Rep: Reputation: 2
Wink

Thanks a bundle DRUUNA & MARKUSH i able to solve the problem with your solutions, sorry for the late reply ! both of you certainly made my day as i was totally frustrated due to this problem!
Thaaaaaaaaanks a bunnnnnndle...!

Here how you solved this problem:

1. First solution [druuna]
:s%F:\\oracle\\app\\oradata%/u002/app/oracle%

-->This solution is good when replacing only one line.

#by mistake I didn't mentioned that there are more than one lines to be replaced.

2. Second solution [markus]
:%s/F:\\oracle\\app\\oradata/\/u002\/app\/oracle/g

-->Replaces all the lines in the file


Thanks again for educating me...!

Last edited by texasj; 07-26-2011 at 12:06 AM.
 
Old 07-26-2011, 01:01 AM   #9
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
You're welcome
 
  


Reply

Tags
replace, vi


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Replacing string using awk gregarion Programming 3 01-19-2010 11:02 PM
Replacing certain parts of a string dipuasks Linux - Server 5 11-22-2008 07:09 AM
replacing string within same file tostay2003 Programming 2 07-06-2007 02:25 AM
Replacing All Instances of a pathname with another in Vi Editor kaplan71 Linux - General 1 06-30-2005 03:54 PM
c++ : replacing a char in a string cb951303 Programming 17 06-06-2005 05:48 PM


All times are GMT -5. The time now is 08:29 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration