Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>using <code>read</code> a single char can be read at a time as follows: </p> <pre><code>read -n 1 c echo $c </code></pre> <p>[ANSWER] </p> <p>Try this: </p> <pre><code>#!/bin/bash # data file INPUT=/path/to/input.txt # while loop while IFS= read -r -n1 char do # display one character at a time echo "$char" done &lt; "$INPUT" </code></pre> <p>From this <a href="http://www.cyberciti.biz/faq/linux-unix-read-one-character-atatime-while-loop/" rel="nofollow">link</a> </p> <hr> <p>Second method, Using <code>awk</code>, loop through char by char </p> <p><code>awk '{for(i=1;i&lt;=length;i++) print substr($0, i, 1)}' /home/cscape/Desktop/table2.sql</code> </p> <hr> <p>third way, </p> <pre><code>$ fold -1 /home/cscape/Desktop/table.sql | awk '{print $0}' </code></pre> <hr> <p><strong>EDIT</strong>: To print each char as <code>HEX</code> number: </p> <p>Suppose I have a file name <code>file</code> : </p> <pre><code>$ cat file 123A3445F </code></pre> <p>I have written a <code>awk</code> script (<code>named x.awk</code>) to that read char by char from <code>file</code> and print into <code>HEX</code> : </p> <pre><code>$ cat x.awk #!/bin/awk -f BEGIN { _ord_init() } function _ord_init( low, high, i, t) { low = sprintf("%c", 7) # BEL is ascii 7 if (low == "\a") { # regular ascii low = 0 high = 127 } else if (sprintf("%c", 128 + 7) == "\a") { # ascii, mark parity low = 128 high = 255 } else { # ebcdic(!) low = 0 high = 255 } for (i = low; i &lt;= high; i++) { t = sprintf("%c", i) _ord_[t] = i } } function ord(str, c) { # only first character is of interest c = substr(str, 1, 1) return _ord_[c] } function chr(c) { # force c to be numeric by adding 0 return sprintf("%c", c + 0) } { x=$0; printf("%s , %x\n",$0, ord(x) )} </code></pre> <p>To write this script I used <a href="http://www.gnu.org/software/gawk/manual/html_node/Ordinal-Functions.html" rel="nofollow">awk-documentation</a><br> Now, You can use this <code>awk</code> script for your work as follows: </p> <pre><code>$ fold -1 /home/cscape/Desktop/file | awk -f x.awk 1 , 31 2 , 32 3 , 33 A , 41 3 , 33 4 , 34 4 , 34 5 , 35 F , 46 </code></pre> <p>NOTE: <code>A</code> value is <code>41</code> in HEX decimal. To print in decimal change <code>%x</code> to <code>%d</code> in last line of script <code>x.awk</code>. </p> <p>Give it a Try!!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload