Re: Help sought for search & replace
am 31.01.2008 01:24:02 von mailto.anand.hariharanOn Jan 29, 3:16=A0pm, Ed Morton
> On 1/29/2008 2:27 PM, Bill Marcum wrote:
>
>
>
>
>
> > ["Followup-To:" header set to comp.unix.shell.]
> > On 2008-01-29, Anand Hariharan
>
> >>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 =3D 2/3; // Some insightful comment
>
> >>becomes
>
> >>C:\My\Source\Tree\Code.cpp:176: x =3D 2/3; // Some insightful comment
>
> >>(note that the three '/' following the second ':' are left untouched,
> >>but all those between the first and second':' are replaced with '\').
>
> > awk -F: '{gsub(/\//,"\\",$2);print}'
>
> awk 'BEGIN{FS=3DOFS=3D":"}gsub(/\//,"\\",$2)1'
>
> or the ":"s would be replaced by " "s.
>
> =A0 =A0 =A0 =A0 Ed.- Hide quoted text -
>
Bill and Ed -
Thank you for your replies. I wish I'd thought outside the box enough
to appreciate that the ':' could be used as field separators.
- Anand