Posts: 4,646
Threads: 1,493
Joined: Sep 2016
i need to make a command that copies stdin to stdout and changes every non-printable character to an escape sequence ... a short one like \n if that character has one, or a hex one. this is so i can look a files that might have a few "strange" characters, to see what it really has, where.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,646
Threads: 1,493
Joined: Sep 2016
i've done that. but repr() doesn't get this "right" in all cases. i know the range it gets "wrong" and could bypass it for those. "right" for what i need is what the Unix/C world does, not what repr() produces.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,646
Threads: 1,493
Joined: Sep 2016
tr can't do it.
sed would be be very awkward. and so would
awk.
C could certainly do i but i'm committed to making things in
Python so they are ready to go on any architecture.
the whole range from chr(7) to chr(13) are 2 character escape sequences. see
man ascii on the nearest BSD or Linux system. 128 to 255 needs to be \xXX. 256 and beyond needs to come out as \Uxxxxxx to cover the whole Unicode (actually in UTF-8 in the file).
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.