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.
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:~> _
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.