Re: Help sought for search & replace
am 29.01.2008 22:16:33 von Ed MortonOn 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 = 2/3; // Some insightful comment
>>
>>becomes
>>
>>C:\My\Source\Tree\Code.cpp:176: x = 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=OFS=":"}gsub(/\//,"\\",$2)1'
or the ":"s would be replaced by " "s.
Ed.