Read character by character in line in which space is also included

Hi friend,

I have one file , and i want to read that file character by character.

I need this script in ksh.

while using read option with -n1 am getting error.

while read -n1 c
 read has bad option

And if i am using below script, then if in a line has space like this ( Pallvi mahajan) Then it stuck after m and loop become iterative after m

typeset -L1 single 
while read line 
do    
 while (( ${#line} > 0 ))    
 do   
      single="$line"        
 # do what you like with $single     
    echo $single        
 line=${line#$single}    
 done 
done < input.txt

Please help me how i can read character by character in line if there is space and any another character are there.

CygWin bash terminal. KSH should wirk...

AMIGA:~> line="This is a string with spaces."
AMIGA:~> n=0
AMIGA:~> while (( $n <= ${#line} )); do echo "${line:$n:1}"; n=$((n+1)); done
T
h
i
s

i
s

a

s
t
r
i
n
g

w
i
t
h

s
p
a
c
e
s
.

AMIGA:~> _

Hi ,

thanks , i have tried but getting error in below statemnet

echo "${line:$n:1}";
bad substitution

if it's ok to use perl

$ printf "abc def    ghi" | perl -ne ' @x = split("",$_); print "$_\n" foreach(@x); '
a
b
c

d
e
f




g
h
i

HI Thanks,

But i have no perl editor

I don't think read -n1 should be a problem in ksh unless you have an old version.

just type

perl -v

on your command line
if it gives output like this, you are good to use the command line provided by me in the other comment

perl -v

This is perl, v5.10.1 (*) built for x86_64-linux-thread-multi

Copyright 1987-2009, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

I am in AIX ksh93 and it did not work.

---------- Post updated at 07:50 AM ---------- Previous update was at 07:48 AM ----------

yes i ran perl -v and it is giving output like this, but i have no idea about perl.

Please let me know if my ouput stored in some variable where i need to put that in ur command instead of print

print abc dbc

---------- Post updated at 07:53 AM ---------- Previous update was at 07:50 AM ----------

can anyone help me getting to under stand what does this command do.

line=${line#$single} 
$line = "whatever your want to print"
printf "$line" | perl -ne ' @x = split("",$_); print "$_\n" foreach(@x); '

but how if i need to fetch this character in loop and need to do another action, then how i can do.

---------- Post updated at 08:07 AM ---------- Previous update was at 08:06 AM ----------

i need to take that character and grep in my file in which i mentioned valid character.

---------- Post updated at 08:49 AM ---------- Previous update was at 08:07 AM ----------

can some please let me know what does this command do

line=${line#$single}    

Try awk if you have

$ echo 'abcdefgh ijk' | awk '{for(i=1;i<=NF;i++)print $i}' FS=""
a
b
c
d
e
f
g
h
 
i
j
k