On Apr 3, 2010, at 03:46 , Scott Haneda wrote:
Just out of curiosity, if I wanted to do something like:
$cat /dev/random | tr "a" "b"

How do I get `tr` to work? I do not see anything in the man page that would allow me to treat the binary data as correctly.

$ LANG=C tr a b </dev/random

If a multibyte localization is configured (OSX and most Linuxes default to UTF8, which is a variable length encoding) then tr will become annoyed when it sees illegal character sequences. In single- byte encodings like ISO8859/1 you're probably fine as long as you don't use things like [:upper:], but LANG=C disables all of this and processes the data as a raw stream of bytes.

tr on many systems was until recently not locale-aware because it was designed internally to deal with bytes, not characters. Recent GNU tr, and BSD tr (which is what OSX uses), were rewritten to be locale- capable. and therefore trip over the illegal-UTF8-sequences problem when used on binary data unless LANG=C is used to disable all locale processing.

--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH



Attachment: PGP.sig
Description: This is a digitally signed message part

_______________________________________________
macports-users mailing list
macports-users@lists.macosforge.org
http://lists.macosforge.org/mailman/listinfo.cgi/macports-users

Reply via email to