Comparing 2 text files & downloading a file if the last lines are different

Hello I'm having a little difficulty in writing a shell script for a few simple tasks.

First I have two files "file1.txt" and "file2.txt" and I want to read and compare the last line of each file. The files look like this.

File1.txt

File2.txt

After comparing the two lines I would like the code to output which line has the higher number. Then depending on which file is outputted I would like to have the script download a file from a URL.

I figured out how to download a file from a URL but I couldn't figure out how to compare two lines and have them output to a variable that would then be used to determine what file to download. Thanks for listening to my ramblings. Any and all help is appreciated.

Here is an approach using awk:

$ awk -F'=' 'NR==FNR{l=$1;m=$2;next}{j=$1;k=$2}END{if(l==j&&m>k) print l,m;if(l==j&&m<k) print j,k}' OFS='=' file1.txt file2.txt
build.number=697

If there is only difference in number and not in text we can simplify it bit :slight_smile:

awk 'NR==FNR{a=$0;next}{b=$0}END{print a>b?a:b}' 1stfile 2ndfile