Computing.Net > Forums > Unix > problem using cat to read data

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

problem using cat to read data

Reply to Message Icon

Name: elpico
Date: January 31, 2005 at 08:43:19 Pacific
OS: solaris
CPU/Ram: 256
Comment:

Hi all,

I'm having problems reading in data from a data file when I use the cat command within a ksh script. I want to read in the whole line at a time, and not lose the spaces within it.

#test.dat

3729 UK
3462 UK
2483 Spain
3567 UK
6747 US
3299 France
4666 UK
4899 UK
7777 Germany
4900 UK


#script.ksh

for val in `cat test.dat`;
do
echo $val
done


Unfortunately that reads in each value at a time - I need to read in the whole line at a time and not lose any spaces - Any idea what I can use?

Thanks,
k.



Sponsored Link
Ads by Google

Response Number 1
Name: thepubba
Date: January 31, 2005 at 08:48:09 Pacific
Reply:

cat test.dat | while read line
do
print $line
done

or better yet, don't use cat. Simply:

exec 3<test.dat
while read -u3 line
do
print $line
done


0

Response Number 2
Name: elpico
Date: January 31, 2005 at 09:12:41 Pacific
Reply:

Thanks for that - Looks good!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Graphic Cards test generation problems



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: problem using cat to read data

how to read in an external text fil www.computing.net/answers/unix/how-to-read-in-an-external-text-fil/3757.html

How to add a java tag to the data www.computing.net/answers/unix/how-to-add-a-java-tag-to-the-data/8362.html

Writing to/reading from 3, 4 etc. www.computing.net/answers/unix/writing-toreading-from-3-4-etc/7388.html