Computing.Net > Forums > Unix > Printing msg after file comparison

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.

Printing msg after file comparison

Reply to Message Icon

Name: sureshht
Date: February 23, 2007 at 08:23:54 Pacific
OS: AIX 5L
CPU/Ram: 4 CPU/8GB RAM
Product: IBM AIX RS6000
Comment:

Hi,
I am comparing 2 files and if any error found i am sending message to tmpfile4 and mailing it to dba team.

counter=1
exec 3< ${tmpfile}

while read -u3 line
do
grep "$line" ${tmpfile3} 1>/dev/null
if [[ $? -eq 1 ]]
then
print "Warning: File $line is missing from the archived log directory !!!" >> $tmpfile4
fi

(( counter += 1 ))
done

Here, If nothing is missing,
I would like to add only one line "nothing is missing" to tmpfile4. How do I do it?
If I include it inside the 'IF condition above, It will print for each line of comparison. I just want to print one line after comparison nothing is found missing.
Any help?

Thanks and Regards
Suresh

sureshht



Sponsored Link
Ads by Google

Response Number 1
Name: thepubba1
Date: February 23, 2007 at 09:33:39 Pacific
Reply:

This worked for me:

#!/bin/ksh

tmpfile=suresh1.data
tmpfile3=suresh2.data

counter=0
exec 3< ${tmpfile}

while read -u3 line
do
grep "$line" ${tmpfile3} 1>/dev/null
if [[ $? -eq 1 ]]
then
print "Warning: File $line is missing from the archived log directory !!!" >> $tmpfile
(( counter += 1 ))
fi

done

if [[ $counter = 0 ]]
then
print "nothing is missing"
fi


0

Response Number 2
Name: thepubba1
Date: February 23, 2007 at 09:36:06 Pacific
Reply:

I can't believe I made such an rookie mistake in my solution. Severe brain cramp.


#!/bin/ksh

tmpfile=lemieux1.data
tmpfile3=lemieux2.data

counter=0
exec 3< ${tmpfile}

while read -u3 line
do
grep "$line" ${tmpfile3} 1>/dev/null
if [[ $? -eq 1 ]]
then
print "Warning: File $line is missing from the archived log directory !!!" >> $tmpfile4
(( counter += 1 ))
fi

done

if [[ $counter -eq 0 ]]
then
print "nothing is missing"
fi


0

Response Number 3
Name: sureshht
Date: February 23, 2007 at 10:55:13 Pacific
Reply:

Hey,
Thanks for your response.
Not working for me.

Thanks
Suresh

sureshht


0

Response Number 4
Name: thepubba1
Date: February 24, 2007 at 13:55:18 Pacific
Reply:

If it is not working, then you have a different issue. If you create data file A and copy it to data file B, you can then run the script I gave you and compare the 2 files. It will print "nothing is missing" since the 2 files are identical. Perhap if you change:

print "nothing is missing"
to
print "nothing is missing" >>$tmpfile4

You'll get the desired result.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Different results from aw... awk summing col1 for simi...



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: Printing msg after file comparison

print columns from files to a file www.computing.net/answers/unix/print-columns-from-files-to-a-file/7615.html

awk - numeric comparison fails www.computing.net/answers/unix/awk-numeric-comparison-fails/8092.html

getting awk to print name of file www.computing.net/answers/unix/getting-awk-to-print-name-of-file-/7206.html