Show whitespace characters in printout
I need to render an ASCII file for printing in a way that removes ambiguity if (very unlikely) one decides to type it in and validate the signatures.
I am giving the 8-bit symbol-set QR code as an alternative, but a manual validation would be a nice addition for archival purposes.
Essentially, I need a monospace typesetter that would typeset a 'blank space' symbol for space, a CR/LF symbol (and proceed to the next line for readability) whenever a CR/LF is encountered, etc., making it obvious if there are any trailing whitespaces before the CR/LF, if there is a character present, etc.
Is there a font that accomplishes that goal? *nix utility? TeX module/package/derived system? I've posted a similar question on TeX.SE, but it might be better suited here.
Solution 1:
As an extension to savanto's answer, I've created a whitespace
bash alias to show whitespace in any output using appropriate Unicode characters. Just pipe to it and have fun!
# SP ' ' 0x20 = · U+00B7 Middle Dot
# TAB '\t' 0x09 = → U+FFEB Halfwidth Rightwards Arrow
# CR '\r' 0x0D = § U+00A7 Section Sign (⏎ U+23CE also works fine)
# LF '\n' 0x0A = ¶ U+00B6 Pilcrow Sign (was "Paragraph Sign")
alias whitespace="sed 's/ /·/g;s/\t/→/g;s/\r/§/g;s/$/¶/g'"
Have fun!
$ bash --help | whitespace
GNU·bash,·version·4.4.20(1)-release-(x86_64-pc-linux-gnu)¶
Usage:→bash·[GNU·long·option]·[option]·...¶
→bash·[GNU·long·option]·[option]·script-file·...¶
GNU·long·options:¶
→--debug¶
→--debugger¶
→--dump-po-strings¶
→--dump-strings¶
→--help¶
→--init-file¶
→--login¶
→--noediting¶
→--noprofile¶
→--norc¶
→--posix¶
→--rcfile¶
→--restricted¶
→--verbose¶
→--version¶
Shell·options:¶
→-ilrsD·or·-c·command·or·-O·shopt_option→→(invocation·only)¶
→-abefhkmnptuvxBCHP·or·-o·option¶
Type·`bash·-c·"help·set"'·for·more·information·about·shell·options.¶
Type·`bash·-c·help'·for·more·information·about·shell·builtin·commands.¶
Use·the·`bashbug'·command·to·report·bugs.¶
¶
bash·home·page:·<http://www.gnu.org/software/bash>¶
General·help·using·GNU·software:·<http://www.gnu.org/gethelp/>¶
Solution 2:
On a unix/linux system, you can pipe the file through tr
, converting certain characters to others. For example:
cat file.txt | tr ' \n' '#$'
will translate all spaces to #
and all newlines to $
.
If you need to transform CR/LF together, you can use tr ' ' '#'
to change spaces, and pipe output into another tr -t '\r\n' '$'
to change the newlines. The -t
tells tr
to truncate the matched set to the length of the replacement set.
You could also use the utility dos2unix
to first translate all the \r\n
line endings to the more unix \n
, then use the first option.
Example (with \n
only):
$ echo "foo bar" | tr ' \n' '#$'
foo#bar$