how do I read from two files

Hi All,

I would like to read the contents of two files using a loop but it doesn't seem to be working. Please have a look at the following script and help me resolve the problem.

While read Rec, Rec1

do
echo $Rec
echo $Rec1
---
----

---
done < file1, file2

I also tried this

for Rec in `cat file1` && Rec1 in `cat file2`
do
echo $Rec
echo $Rec1
---
----
done

Thanks

Do you want to read all of file, then all of file2; or read one record from file1 then one record from file2

I want to read one record from file1 and one record from file2

Try this:


IFS="|"

paste -d\| file1 file2 |
while read line1 line2 ; do

  echo FILE1: $line1
  echo FILE2: $line2

done

thank you quirkasaurus!

quirkasaurus,

I have one more problem with this script, how do know the EOF in shell scripts.
I don't want to display the records if one of the files reaches the end.

Thanks

IFS="|"

paste -d\| file1 file2 |
while read line1 line2 ; do

  if [ -z "$line1" ]; then
    break
  fi

  if [ -z "$line2" ]; then
    break
  fi

  echo FILE1: $line1
  echo FILE2: $line2

done

This'll terminate as soon as one file has a blank line or EOF...
is that good enough?

I tried writing the condition if [ $line1 <> " " ], but it did not help.
Your solution helps. great !! thanks

yup.

if [ $line <> "" ]; then...

is not valid ksh.

not-equals for strings is: !=