SlackwareThis Forum is for the discussion of Slackware Linux.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I may end up re-writing my code from Bash to Python. That will change things quite a bit. Then it will be easy to have the entire list of packages in a dictionary indexed by version and non-version base names giving full path.
I took a sequential approach using sorted input rather than go down that route. My script (it's a system update aid akin to slackpkg but with a different approach) offloads most the gruntwork to join, comm, and sort.
root@ws1:~# time slacklist upgrade install
0.157s elapsed to compare the packages installed on my system to those available on my local mirrors. Can't be bad.
Originally I used only bash internals to manipulate the data (along the lines of the example gnashley made earlier) and it was much slower than sorting and using join, comm and such.
I briefly considered recoding it in perl but what I have works so well I couldn't really see the point and it's nice having runtime requirements that are only bash + coreutils.
Yep, gnashley's approach is what I normally use in these situations. Bash isn't very efficient when running these sort of manipulations but unless you're processing vast amounts of data it won't really matter.
Here's two different approaches to what I was doing above
gazl@ws1:~$ cat /tmp/testing.sh
while read path
echo $pkgbase $pkgver $path
done < <( find /local/slackware/slackware64-current/slackware64 -name "*.t?z" | sort)
gazl@ws1:~$ time /tmp/testing.sh >/dev/null
gazl@ws1:~$ cat /tmp/testing2.sh
sed -e 's:^\(.*/\)\(.*\)-\([^-]*\)-\([^-]*\)-\([0-9]\+\)\(.*\)\(\.t.z\)$:\2 \2-\3-\4-\5\6 \1\2-\3-\4-\5\6\7:'
find /local/slackware/slackware64-current/slackware64/ -name "*.t?z" | sort | reformat_available
gazl@ws1:~$ time /tmp/testing2.sh >/dev/null
As you can see, the sed version is much faster and uses less cpu -- though neither are slow enough for it to matter for such a small amount of input data. The reason I used sed in my script was because it was already using 'join','comm' and 'sort' so having an external dependency on sed really didn't make much difference ( plus it was a bit of an experiment ).
P.S. Of course, the bash version is infinitely more readable than the sed/regex.
Last edited by GazL; 10-01-2013 at 04:26 AM.
Reason: fixed typo