Compare values from 2 tab seperated files

Watnog
Watnog used Ask the Experts™
on
I had this question after viewing Unix AIX compare column of 2 files.

Hi Experts,
I try to make these lines work:

#!/bin/ksh
file1=file1.txt
file2=file2.txt
while read LINE ; do
FileSystem=`echo $LINE | awk '{print $3}'`
GrowthTreshold=`echo $LINE | awk '{print $5}'`
if [ "$GrowthTreshold" -ge 0 ] 2>/dev/null  ; then
echo $GrowthTreshold
perl -ane '$k=$F[0].$F[2]; print if exists($h{$k}) && $F[3]-$h{$k}>='$GrowthTreshold'; $h{$k}=$F[3]' $file1 $file2 >>ExceptionList.txt
else
echo ""$FileSystem" could not be checked"
fi
done <$file1.txt

###

I attach a file1.txt and a file2.txt

Values of file2.txt are compared to those of file1.txt
In this example:
- the first line is one that should be logged: 78 to 88 = 10 so that exceeds the allowed growth treshold of 5
- and also the last line: 34 to 40 = 6 so that exceeds of the allowed growth treshold of 5

When I run the script as it is now this is returned:

...
syntax error at -e line 1, near ">=;"
Execution of -e aborted due to compilation errors.


Thank you for your help.
Watnog
file1.txt
file2.txt
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Looks like you have a quoting issue with your one-liner.

Remove the single quotes around the $GrowthTreshold var.  If quotes are really needed by the shell, then use double quotes around that var.

EDIT:
Personally, I'd drop the shell script and do everything in a perl script.
In case it's not clear why I said to change the quotes, that first single quote around the $GrowthTreshold var is terminating the one-liner leaving it incomplete and giving the error.

Author

Commented:
Thanks FishMonger, as EE is my last resort, I did play with the quotes as I know that's tricky.
Anyway, copying the quotes from a place where the same line does work did the trick (reading the var), I have no explanation for that.

I have another problem, the perl line if it finds a match prints the entire file, it should only print the matching line.
If you'd have some more time to check into I'd be very grateful.
If you have a better solution altogether, that's fine too of course.

Watnog

Author

Commented:
Well, I hope I don't hurt your feelings, but I kind of regressed, dropped the perl line and have it done shell-wise.
One of the advantages is that at least I understand (better) what and how things are done.

This means you are free.
Thanks very much all the same. it's great to know there's an expert in case you'd get completely lost.
Commented:
Old school. Nothing to be proud of or worth sharing.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial