Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How change default setting for read

Status
Not open for further replies.

longs

Programmer
Jul 27, 2007
31
US
Hi all
I have a small problem Let me explain myself with an example

I have a text file “test.txt”
cat test1.txt
D1Helloo How are you doing???
TCklsjdf9098 809809 23423298098098 909809809098
D1kkdjd098234908 9084235098345908 092838
D1230498234098 0990823 980080809809 0980982349875289

But when I try to perform something like this

#!/usr/bin/ksh

cat test1.txt | while read line
do
if [ `echo $line | grep -c "^D1"` -gt 0 ] ; then
print "there are D1 records"
print `echo $line`
fi
done

but the output for this little script is;

there are D1 records
D1Helloo How are you doing???
there are D1 records
D1kkdjd098234908 9084235098345908 092834098908234098
there are D1 records
D1230498234098 0990823 980080809809 0980982349875289

If you see that all the spaces are getting changed to single space. As per my knowledge, by default read takes spaces as field delimiter. So I have the out of the script same as the original file.

Thanks for your help in advance
Longs
 
Replace this:
print `echo $line`
with either this:
print "$line"
or this:
echo "$line"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top