How to read character by character using awk
Either use fold -1 then pipe into awk, or loop through each character in awk, e.g....
$ cat file1
abc
$ fold -1 file1 | awk '{print $0}'
a
b
c
$ awk '{for(i=1;i<=length;i++) print substr($0, i, 1)}' file1
a
b
c
What shell? Bash has the `read` builtin where you can do:
while read -n1 char; do
#do something with the byte in $char
done <input.file
could u explain what is "-n1" here in this syntax
So -n1 means reading character by character.
Regards,
Chella
what exactly the "number 1" do in the syntax
if i give 2 what will happen .... does it read 2 chars at a time
can u explain it little bit clear
regards
srikanth
Bash has a manual page and a built-in help system.
bash$ help read
...
If -n is supplied with a non-zero NCHARS argument, read returns after NCHARS
characters have been read.