LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Search this Thread
Old 09-30-2013, 12:30 PM   #16
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Slackware, CentOS, Ubuntu, Fedora, Timesys, Linux From Scratch
Posts: 1,777
Blog Entries: 20

Original Poster
Rep: Reputation: 115Reputation: 115

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.
 
Old 09-30-2013, 01:59 PM   #17
GazL
Senior Member
 
Registered: May 2008
Posts: 3,392

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
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.

Code:
root@ws1:~# time slacklist upgrade install
/local/slackware/extras/packages/kernel-3.11.0-custom-none-x86_64-1_local.txz
/local/slackware/slackware64-current/slackware64/a/kernel-generic-3.10.12-x86_64-1.txz
/local/slackware/slackware64-current/slackware64/a/kernel-huge-3.10.12-x86_64-1.txz
/local/slackware/slackware64-current/slackware64/a/kernel-modules-3.10.12-x86_64-1.txz
/local/slackware/slackware64-current/slackware64/k/kernel-source-3.10.12-noarch-1.txz

real    0m0.157s
user    0m0.113s
sys     0m0.010s
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.
 
Old 10-01-2013, 02:53 AM   #18
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,757

Rep: Reputation: 468Reputation: 468Reputation: 468Reputation: 468Reputation: 468
Really, rev|cut|rev?, awk?? python??? What could be simpler than:
Code:
PKG='sysvinit-functions-8.53-x86_64-2.txz'
echo NAME=${PKG%-*-*-*}
 
2 members found this post helpful.
Old 10-01-2013, 03:11 AM   #19
Didier Spaier
Senior Member
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slackware{,64}-{14.1,current} on a Lenovo Thinkpad T61 6457-4XG
Posts: 4,287

Rep: Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062
Quote:
Originally Posted by gnashley View Post
Really, rev|cut|rev?, awk?? python??? What could be simpler than:
Code:
PKG='sysvinit-functions-8.53-x86_64-2.txz'
echo NAME=${PKG%-*-*-*}
+1. And this should work with any POSIX compliant shell.
 
Old 10-01-2013, 03:51 AM   #20
ponce
Senior Member
 
Registered: Aug 2004
Location: Pisa, Italy
Distribution: Slackware
Posts: 2,447

Rep: Reputation: 877Reputation: 877Reputation: 877Reputation: 877Reputation: 877Reputation: 877Reputation: 877
Quote:
Originally Posted by gnashley View Post
Code:
PKG='sysvinit-functions-8.53-x86_64-2.txz'
echo NAME=${PKG%-*-*-*}
http://i.imgur.com/j74SykU.gif
Attached Images
File Type: jpg neat2.jpg (15.7 KB, 5 views)

Last edited by ponce; 10-01-2013 at 03:54 AM.
 
Old 10-01-2013, 03:58 AM   #21
GazL
Senior Member
 
Registered: May 2008
Posts: 3,392

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
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
Code:
gazl@ws1:~$ cat /tmp/testing.sh
#!/bin/bash

while read path
do
  pkgfile="${path##*/}"
  pkgver="${pkgfile%.t?z}"
  pkgbase="${pkgver%-*-*-*}"
  echo $pkgbase $pkgver $path
done < <( find /local/slackware/slackware64-current/slackware64 -name "*.t?z" | sort) 

gazl@ws1:~$ time /tmp/testing.sh >/dev/null

real    0m0.077s
user    0m0.053s
sys     0m0.023s
gazl@ws1:~$ cat /tmp/testing2.sh
#!/bin/bash

function reformat_available()
{   
   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

real    0m0.028s
user    0m0.027s
sys     0m0.000s
gazl@ws1:~$
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
 
Old 10-01-2013, 05:09 AM   #22
diwljina
Member
 
Registered: Jun 2009
Distribution: Slackware, Debian
Posts: 105

Rep: Reputation: 8
Wrong post, didn't read the question right.

Last edited by diwljina; 10-01-2013 at 05:10 AM. Reason: Wrong post
 
Old 10-01-2013, 12:41 PM   #23
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,757

Rep: Reputation: 468Reputation: 468Reputation: 468Reputation: 468Reputation: 468
"bash version is infinitely more readable than the sed/regex" in this case by a lot! But often it is the other way around.
 
Old 10-02-2013, 03:50 PM   #24
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Slackware, CentOS, Ubuntu, Fedora, Timesys, Linux From Scratch
Posts: 1,777
Blog Entries: 20

Original Poster
Rep: Reputation: 115Reputation: 115
Quote:
Originally Posted by gnashley View Post
"bash version is infinitely more readable than the sed/regex" in this case by a lot! But often it is the other way around.
Indeed. But this was a new one for me. Glad you guys jumped in with it.
 
Old 10-02-2013, 04:31 PM   #25
Didier Spaier
Senior Member
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slackware{,64}-{14.1,current} on a Lenovo Thinkpad T61 6457-4XG
Posts: 4,287

Rep: Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062
This one, found in pkgtool and copyright Patrick Volkerding, maybe hard to read but is super fast!
Code:
create_list_of_installed_packages()
{
        FILES=$(ls $ADM_DIR/packages)
      if [ -n "$FILES" ]; then
      cd $ADM_DIR/packages
      { grep '^PACKAGE DESCRIPTION:$' -Z -H -m1 -A1 $FILES; echo; } \
      | sed -n 'h;n;/\x00/{h;n;};x;s/  */ /g;s/ $//;s/[\"`$]/\\&/g
       s/\(.*\)\x00\([^:]*:\)\? *\(.*\)/ "\1" "\3" "View information about package \1" \\/;p' > $TMP/list_of_installed_packages \

      fi
}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fedora 15 - Changing Eth Device Naming Scheme! zer0signal General 10 01-26-2011 06:46 PM
[SOLVED] Ubuntu Karmic: How do I use the sdX naming scheme instead of UUID? lupusarcanus Linux - Newbie 7 03-15-2010 11:52 PM
Ubuntu Package Naming Suggestion Mr. Swillis Linux - General 14 08-02-2008 09:07 PM
Is there a way to have grub translate its own naming to naming scheme under Linux zhjim Linux - Software 6 05-28-2006 08:09 AM
Mandrake adopts new roadmap and naming scheme TravisOSF Linux - News 7 03-28-2005 10:30 AM


All times are GMT -5. The time now is 05:40 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration