LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   problem in replacing string in vi editor (https://www.linuxquestions.org/questions/linux-newbie-8/problem-in-replacing-string-in-vi-editor-893275/)

texasj 07-23-2011 12:56 AM

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......!

druuna 07-23-2011 01:23 AM

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.

markush 07-23-2011 01:58 AM

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

druuna 07-23-2011 02:12 AM

Hi markush,
Quote:

Originally Posted by markush (Post 4422988)
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).

markush 07-23-2011 02:21 AM

Quote:

Originally Posted by druuna (Post 4422994)
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

druuna 07-23-2011 02:30 AM

@markush: :)

The OP now has 2 ways of solving his/her problem!

markush 07-23-2011 02:36 AM

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

texasj 07-26-2011 12:00 AM

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...!;)

druuna 07-26-2011 01:01 AM

You're welcome :)


All times are GMT -5. The time now is 09:37 AM.