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
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