#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    3
    Rep Power
    0

    Revision number comparison


    Hi,

    I am in the process of writing a shell script - basically i currently write the contents of a directory(which contains certain packages) to a text file . something along the lines of this

    ls -ltr ${DIR} > /tmp/list.txt

    what i need to do is from this list find out which packages are the latest revision as there could be multiple versions of one package.

    Any direction would be appreciated
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,451
    Rep Power
    1751
    The most obvious, and actually not facetious, reply would be ... given the data you see on the screen with the directory listings, how would you do it?
    Are the packages all in their own separate directories? Do the directory names include a version number? Is the date stamp for last modification date on the directory 'stable' enough to show correct age of install?
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    3
    Rep Power
    0
    In this instance we can assume all the packages are in the same directory- And yes they contain revision numbers - i understand that finding the highest (although not necessarily the best option) rev num would supply me with the most recent package.

    my issue is how do i find this for each package in the case of there being multiple different packages in this directory
    i.e

    package1_revnum1
    package1_revnum2
    package1_revnum3
    package2_revnum1
    package2_revnum2


    where i would want to take both package1_revnum3 and package2_revnum3

    thanks for the reply
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,451
    Rep Power
    1751
    Could approach is a few ways, but my best guess would be:
    Chuck it through awk (using field delimiter of _) and using an array keyed on package name (in field 1) compare version numbers (field 2), storing only if higher.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    3
    Rep Power
    0
    Originally Posted by SimonJM
    Could approach is a few ways, but my best guess would be:
    Chuck it through awk (using field delimiter of _) and using an array keyed on package name (in field 1) compare version numbers (field 2), storing only if higher.
    Simon,

    That was my initial idea although i found a simpler solution, i was able to write the contents of the directory to a .txt file ( ls -tr directory > file.txt ) and then in a for loop `grep "${package}_" file.txt | tail -n1`

    This solution would take the last package that was modified.

    Thank you for your help

IMN logo majestic logo threadwatch logo seochat tools logo