Re: Help sought for search & replace

Anand Hariharan wrote:
> On Jan 30, 1:11 pm, James Hu <j... [at] despammed.com> wrote:
>
>>On Jan 29, 9:17 am, Anand Hariharan <mailto.anand.hariha... [at] gmail.com>
>>wrote:
>>
>>
>>>I would like to replace all occurrences of '/' by '\' -- but only
>>>those instances of '/' within that portion of a line between the first
>>>and second ':'.
>>
>>>Example:
>>
>>>C:/My/Source/Tree/Code.cpp:176: x = 2/3; // Some insightful comment
>>
>>>becomes
>>
>>>C:\My\Source\Tree\Code.cpp:176: x = 2/3; // Some insightful comment
>>
>>Something along the lines of:
>>
>>:s-: -:^V^M-|-1s-/-\\-g|j
>>
>>should do the trick.
>>
>
>
> Just in case my post gave the wrong impression, I have very many such
> lines in each of a handful of files. Your solution works for *one*
> line.
>
> - Anand

:1,2s-: -:^V^M-|-1s-/-\\-g|j

Now it works for 2 lines.

More vim :

Current file :
:%s+\v(^[^:]*:[^:]*) [at] <=/+\\+g

All loaded files :
:bufdo %s+\v(^[^:]*:[^:]*) [at] <=/+\\+g

Scriptlike :
I.)
$ vim -esc ':argdo %s+\v(^[^:]*:[^:]*) [at] <=/+\\+g|wqa' file1 file2 ...

II.)
$ cat my_subst.vim
argdo %s+\v(^[^:]*:[^:]*) [at] <=/+\\+g
wqa
$ vim -esS my_subst.vim file1 file2 ...

-m
muede [ Do, 31 Januar 2008 03:29 ] [ ID #1920581 ]

Re: Help sought for search & replace

muede73 wrote:
> Anand Hariharan wrote:
>
>> On Jan 30, 1:11 pm, James Hu <j... [at] despammed.com> wrote:
>>
>>> On Jan 29, 9:17 am, Anand Hariharan <mailto.anand.hariha... [at] gmail.com>
>>> wrote:
>>>
>>>
>>>> I would like to replace all occurrences of '/' by '\' -- but only
>>>> those instances of '/' within that portion of a line between the first
>>>> and second ':'.


Current file :
:%s+\v(^[^:]*:[^:]*) [at] <=/+\\+g

All loaded files :
:bufdo %s+\v(^[^:]*:[^:]*) [at] <=/+\\+ge

Scriptlike :
I.)
$ vim -esc ':argdo %s+\v(^[^:]*:[^:]*) [at] <=/+\\+ge|wqa' file1 file2 ...

II.)
$ cat my_subst.vim
argdo %s+\v(^[^:]*:[^:]*) [at] <=/+\\+ge
wqa
$ vim -esS my_subst.vim file1 file2 ...

Better add the 'e' flag.

-m
muede [ Do, 31 Januar 2008 11:52 ] [ ID #1920592 ]
Linux » comp.unix.shell » Re: Help sought for search & replace

Vorheriges Thema: Annoying terminal characters
Nächstes Thema: grep and shell substituion