Direct the output of a script to a log file

Hi,

I have a script to compare 2 files.

file1=$1
file2=$2

num_of_records_file1=`awk ' END { print NR } ' $file1`
num_of_records_file2=`awk ' END { print NR } ' $file2`

i=1
while [ $i -le $num_of_records_file1 ]
do
sed -n "$i"p $file1 > file1_temp
sed -n "$i"p $file2 > file2_temp

diff file1_temp file2_temp>file_temp

echo "Comparing $i line of fil1 with file2:"
awk NR==2 file_temp|sed 's/</Old:/g'
awk NR==4 file_temp|sed 's/>/New:/g'
i=`expr $i + 1`
done

It gives o/p like
Comparing line no. 1 of file1 with file2
old:
New:

I want to direct the o/p of the script to a log file which should be saved as <filename>.log

e.g If here file1 is personel,the log file should be personel.log

Thanks In advance

done >$1.log

Easiest way is to do it on the command line; otherwise you need to modify your script script in numerious places to redirect output to a log file.

Suppose your shell script is named compare and file2 is named personel.bak, you could redirect output to a log file as follows:

compare personel personel.bak > personel.log 2>&1

Thanks.. done >$1.log worked

How can zip the log the file?

done >$1.log
tar -czf "$1.log" >"$1.zip"

Only it's a ".tar.gz", not a ".zip" then. (.zip is customarily the extension for files compressed with PKzip, or a compatible program such as WinZip or InfoZIP, aka Unix zip.)