in reply to Slightly OT - Matching a strange character

on unix you may use od -c <filename> to get a dump of all of the characters escaped. output is something like this:
% head -2 /etc/hosts ## # Host Database % head -2 /etc/hosts | od -c 0000000 # # \n # H o s t D a t a b + a 0000020 s e \n + 0000023


-Waswas

Replies are listed 'Best First'.
Re: Re: Slightly OT - Matching a strange character
by graff (Chancellor) on May 20, 2004 at 02:14 UTC
    Right -- though a hex dump tends to be more useful in cases like this. And of course, if the odd byte happens to be near the end of a large file, this approach can be tedious...

    Here's my favorite -- it prints a histogram of byte values in a data stream or file:

    #!/usr/bin/perl use strict; my @ch; while (<>) { $ch[ord()]++ for ( split( // )); } printf "%6d %.2x\n", $ch[$_], $_ for ( grep {$ch[$_]} 0..$#ch );
    And it would be easy to make a couple additions/alterations so that it tabulates utf8 characters instead of bytes.
Re: Re: Slightly OT - Matching a strange character
by ambrus (Abbot) on May 20, 2004 at 11:54 UTC

    Or just cat -v?