Thursday, July 28, 2011

Re: substitute pb

On 07/28/2011 03:07 PM, niva wrote:
> Using net view command on windows provide me the following output:
>
> \\255.255.255.255\d$\DIR some text
>
> I would like to substitute this network path \\255.255.255.255\d$\DIR
> to the output.
>
>
> I have done this assuming path is \\255......\DIR
>
> let pattern=substitute(path,'\\','\\\\','g')
> let pattern=substitute(pattern,'\$','\\$','')
> let pattern=substitute(pattern,'\.','\\.','')
>
> this works fine and obtain this \\\\255\.255\.255\.255\\d\$\\DIR when
> I echo pattern var.
>
> Now I launch substitute(output,pattern,'','g') andit fails, my output
> is still
> \\255.255.255.255\d$\DIR some text

Having read your post multiple times, I'm not quite sure what
you're trying to do, and what your inputs/outputs are. It
_sounds_ like you're trying to use the output of "net view" on a
Windows box to find some share's UNC path, then use that as a
pattern to do a substitute in your file.

For simplification, I suggest using escape() to add backslashes
where you want them.

So assuming that you have

:let path='\\255.255.255.255\d$\DIR some text'
:let pattern=escape(path, '$.\')

You now have "pattern" with the search pattern. You say that you
"launch substitute(...)", but you don't say what you launch it
against. If you want to run it against your file, you can do
something like

:let @/=pattern
:%s///g

which will delete all instances of "pattern" in the current file.
If you don't need the pattern for anything else, you can
directly assign it:

:let @/=escape(path, '$.\')

If you have variables (e.g. "data") and you want to mung them,
you can use something like one of these:

:let data=substitute(data, pattern, '', 'g')
:let data_new=substitute(data_orig, pattern, '', 'g')

Without further details, it's a bit hard to offer much more
assistance.

-tim


--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: