The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 08-29-2008
chella chella is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 75
read a file line by line in ksh

Hi,

In ksh we use 'while read line' statement to read a file line by line. In my input file I have 5 spaces appended at the end of each line. When I use while read line statement it chops off the spaces at the end of each line

Inp.txt
aaaa<five spaces>
bbbb<five spaces>
cccc<five spaces>

pgm.ksh
#!/bin/ksh
while read line
do
len=`echo "$line" | wc -c`
echo $len
done

my_output
5
5
5

But my expected output should be,
10
10
10

Kindly help me on this.

Thanks in advance,
Chella.