Re: sed conversion of digits to "x"

From: Ed Morton (morton_at_lsupcaemnt.com)
Date: 11/23/05


Date: Tue, 22 Nov 2005 18:32:59 -0600

Ed Morton wrote:

> James wrote:
>
>> In perl,
>> $ cat conv.pl
>> sub f {
>> my $s = shift; $s =~ s/\d/x/g; return $s
>> }
>> while (1) {
>> if (/ [\d\.]+ /) {
>> print $`.f($&); s/^$`$&//
>> } else {
>> print; last
>> }
>> }
>>
>> $ echo " 12.3 a1b2 foo12 3.4 5.67 " | perl -n conv.pl
>> xx.x a1b2 foo12 x.x 5.67
>
>
> Ahem: notice that final 5.67 in your output....

It'll also wrongly convert " 1.2.3 " to " x.x.x ".

        Ed.