Computing.Net > Forums > Unix > how to read in an external text fil

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.

how to read in an external text fil

Reply to Message Icon

Name: Matt Harrill
Date: September 6, 2002 at 01:39:18 Pacific
OS: NT
CPU/Ram: P1/64k
Comment:

Hi

I have tried diff, and it does not give me what i need. I am unsure of the code needed to read in one line at a time of an external file and then use fields from that line to assign to variables. Those variables wold then be passed into an awk with the other file to be compared - can anybody help me please?

Regards

Matt Harrill



Sponsored Link
Ads by Google

Response Number 1
Name: tom z.
Date: September 6, 2002 at 03:27:36 Pacific
Reply:

If you already know awk, then the most of the issue is solved. Just use awk to read in a line at a time and to assign the designate values to their respective variables.

Hope this helps, good luck.


0

Response Number 2
Name: James Boothe
Date: September 6, 2002 at 06:46:22 Pacific
Reply:

Yes, instead of processing one line at a time and calling awk repeatedly, awk can read both of your files and do the diff logic. I could provide a solution if you provide more detail (sample from both files, how you want them matched, estimated file sizes).

But to answer your question, following code will read one line at a time from a file and assign fields to variables:

#!/bin/sh
cat myinputfile |
while read var1 var2 var3 remainder
do
echo "var1=$var1 var2=$var2 var3=$var3"
done
exit 0


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







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: how to read in an external text fil

How to Read .txt file and edit www.computing.net/answers/unix/how-to-read-txt-file-and-edit/7947.html

how to read a file www.computing.net/answers/unix/how-to-read-a-file/8202.html

how to find in which shell you are www.computing.net/answers/unix/how-to-find-in-which-shell-you-are/3491.html