bash - Viewing the ASCII codes of piped-in characters

07
2014-07
  • JJ56

    Is there a command that would let me see ASCII values of characters outputted from a program?

    Say I pipe in a NUL character and a p, could I get a 0 and a 112 out?

  • Answers
  • flolo

    You can use od -t d1 to output the ascii values of a file. When using this, he starts the first column with the offset within the stream (the adress), when you dont need it, you can pipe it into cut -d \ -f 2- or similar.


  • Related Question

    unix - Can the output of one command be piped to two other commands?
  • Richard Hoskins

    How can I pipe the output of one command to the input of two other commands simultaneously?


  • Related Answers
  • Ben

    It sounds like the tee command will do what you want.

    The key is to use

    >( )
    

    for process substitution. With tee, use the following pattern:

    tee >(proc1) >(proc2) >(proc3) | proc4
    

    So if you wanted to use the output of ls as input to two different grep programs, save the output of each grep to different files, and pipe all of the results through less, try:

    ls -A | tee >(grep ^[.] > hidden-files) >(grep -v ^[.] > normal-files) | less
    

    The results of the ls -A will "piped" into both greps. The file hidden-files will have the contents from the output of the first grep, and normal-files will have the results of the second grep. All of the files will be shown in the pager less.

    source

  • Peter Mortensen

    Use "tee".

    Example:

    grep someSearchString someFile | tee /dev/tty | wc -l > grepresult
    

    This will send the output of the grep command to both the terminal and to wc (whose output is in turn redirected to the file grepresult).

    "Tee" is explained in the Wikipedia article tee (command). Central is: "The tee command reads standard input, then writes its content to standard output and simultaneously copies it into the specified file(s) or variables.".