Re: Help sought for search & replace

Anand Hariharan 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

perl -pe's{(:.+?:)}{($a=$1)=~y[/][\\];$a}e' yourfile


John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
someone [ Di, 29 Januar 2008 22:02 ] [ ID #1918712 ]

Re: Help sought for search & replace

Anand Hariharan wrote:
> On Jan 29, 3:02 pm, "John W. Krahn" <some... [at] example.com> wrote:
>> Anand Hariharan 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
>> perl -pe's{(:.+?:)}{($a=$1)=~y[/][\\];$a}e' yourfile
>>
>
> Thanks, John. I like your perl one-liners that you post in c.u.s.
>
> Could you point me to the chapter in Programming Perl (or some other
> online reference) that explains the s{}{}e syntax?

http://perldoc.perl.org/perlop.html#s%2fPATTERN%2fREPLACEMEN T%2fmsixpogce

http://perldoc.perl.org/perlretut.html

http://perldoc.perl.org/perlre.html

Note that these pages cover Perl version 5.10.0 which you may not have
installed yet on your computer. If you do have Perl installed then you
should have the documentation installed as well which you can access
from the command line like so:

perldoc perlop

perldoc perlretut

perldoc perlre



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
someone [ Do, 31 Januar 2008 02:21 ] [ ID #1920580 ]
Linux » comp.unix.shell » Re: Help sought for search & replace

Vorheriges Thema: grep and shell substituion
Nächstes Thema: Re: Help sought for search & replace