Hello,
I’m stuck on this issue where i need to compare Decimal number’s in unix shell script.
Example:
Want to compare file versions
version of “File1” is 11.5.69
version of “File2” is 11.5.70
Now File2 is a newer version , and now if i compare File1 and File2 it should show me File2 is greater.
Kindly help me on this.
Thanks in advance.
Rajz
Since the version i.e.11.5.70 is not a valid number, I think you’ll have to break each file’s version number into 3 tuplets and compare each one. It’s a kludge, but here is one way to do it:
Of course, the limitation is that each version has to be 3 tuplets.
Second:
I am not familiar with the command adident, so I cannot comment on that. However, you can also get the version from the included string using awk; it’s the 3rd field:
echo ” $Header: OEXVHLSB.pls 115.10 2002/12/05 18:38:07 ” |awk ‘ { print $3 } ‘
You can also get the date and time string; it’s the 4th and 5th fields:
echo ” $Header: OEXVHLSB.pls 115.10 2002/12/05 18:38:07 ” |awk ‘ { print $4 $5 }
‘
Including a datetime comparison is not simple; IMO, it involves changing the datetime to the number of seconds since the unix epoch, Jan 1, 1970, which isn’t easy using classic unix tools (i.e. non-GNU tools). To perform epoch calculations, I use perl. Here is an example post:
https://computing.net/answers/pr…
Date conversion has been discussed a lot on computing.net. Perform this google for many examples:
site:computing.net epoch