Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a program which displays incoming data which is delimited by a null character (^A). I am accessing the server it is running on via PuTTY and When I open a log in a text editor these are visible, however the null characters seem to be skipped when displayed from standard output, and this makes the data very hard to interpret as it is impossible to distinguish where one field ends and the other begins, is there any way I can configure PuTTY to display SOMETHING when a null character is printed to standard output?

Edit: example in PuTTY (portions of FIX protocol if anyone is curious)

614=-200015=USD17=80100309720=022=129=430=O31=18.00000032=2300037=000000000038=039=140=2

How a message looks in vi (^A shows up in blue making it much easier to read):

A14=0^A15=USD^A17=801000096^A20=0^A22=1^A29=1^A30=O^A31=158.927881^A32=3200^A37=0000000000^A38=0^A39=2

And ideally if i replace null with say a space it is finally somewhat understandable from a glance:

14=0 15=USD 17=801000096 20=0 22=1 29=1 30=O 31=158.927881 32=3200 37=0000000000 38=0 39=2
share|improve this question
1  
Can't you use tr or sed to make them visible before feeding to the editor? Vim could also filter the input ... –  0xC0000022L Mar 8 '13 at 20:58
    
I would ideally like to see them in the shell without having to use an editor. I can open the log files with an editor and null chars are visible so the messages are readable, however there is a significant delay from when a message is sent and when it is logged, and I often need to immediately interpret messages as they come in... –  Shouvik Sayef Mar 8 '13 at 21:01
1  
^A is not the null character, the null character is ^@. ^A is the first character after the null character. –  Darth Android Mar 8 '13 at 21:41
    
So I have found this is impossible without modifying the program. 001 is the SOH character is not displayed in any character set. In terms of modifying the logs the tr command did the trick. Thank you –  Shouvik Sayef Mar 13 '13 at 14:52

2 Answers 2

Substitute the unprintable charaters with something readable.

before

$ find  -print0
../03.lines./04.lines./02.lines./01.lines$

after

$ find  -print0 | sed 's/\0/  /g'
../  3.lines./  4.lines./  2.lines./  1.lines$
share|improve this answer

Use stdbuf (from coreutils) and tr:

$ while true; do printf "ASDF\001"; sleep 0.5; done | stdbuf -o0 tr '\001' ' '
ASDF ASDF ASDF ASDF ASDF ...

Note: stdbuf is not needed when replacing with a newline, ie tr '\001' '\n'

Or, use awk/gawk

$ while true; do printf "ASDF\001"; sleep 0.5; done | awk 'BEGIN{RS="\001"}; {printf "%s ", $0}'
ASDF ASDF ASDF ASDF ASDF ...

This works irrespective of terminal. See What is buffering... for more information.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.