[pm-h] Change character code 160 to 32

Todd Rinaldo toddr at null.net
Tue Oct 6 07:34:32 PDT 2009


On Sun, Oct 4, 2009 at 3:21 PM, Mike Flannigan <mikeflan at att.net> wrote:
>
> Mike Flannigan wrote:
>>
>> I want to change character code 160 to character
>> code 32 throughout a bunch of text files.  I'm using
>> this right now
>> s/(.)/ord($1) == '160' ? chr(32) : $1 /eg;
>> and it works, but I don't like it much.  If anybody
>> has another way they like better, I'd appreciate
>> seeing it.  It does not have to be a reg exp.
>>
>> Anybody know why this doesn't work?
>> tr/\160/\32/d;
>> Oddly it replaces 'p' (character code 80) with
>> character code 26???
>
>
> This works:
>
> tr/\xA0/\x20/
>
> Apparently that is hexidecimal notation.
>
>
> Mike

Mike, I ran across this as a more broad solution in my code. It
leverages the POSIX printable character set.

The below will replace all non-printable characters with "."
s/\P{IsPrint}/./g;

Todd


More information about the Houston mailing list