DaemonForums  

Go Back   DaemonForums > OpenBSD > OpenBSD General

OpenBSD General Other questions regarding OpenBSD which do not fit in any of the categories below.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1   (View Single Post)  
Old 31st August 2019
ip6ix's Avatar
ip6ix ip6ix is offline
Real Name: Neil
Port Guard
 
Join Date: Sep 2017
Location: Wales, UK
Posts: 45
Default Sorting installed packages by size

I was looking through the various man pages (pkg_* especially pkg_info(1)) trying to find an option where I could get a sorted list by size, of installed packages. pkg_info(1) has the "-s" option to output size, but no sorting.

Clearly some text munging was needed, with the use of pipes. Here's what I came up with:

Code:
pkg_info  -a -s | sed '/^$/d' | paste - - | sort -k 5 -n -r \
  | sed 's/^Information for inst://g' | awk '{print $3 "\t\t" $1};' \
  | numfmt --to=si
The first two parts get a list of installed packages plus size, removing empty lines, then I use paste(1) to join adjacent lines, do a reverse numeric sort on the 5th field, remove unneeded stuff, then print lines with fields in "size package" order.

numfmt(1) converts bytes to human-readable form and can be omitted if you don't have GNU coreutils installed, in which case the awk(1) command could be extended to do the conversion.

Pipes are one of the core components of the UNIX philosophy / way-of-doing-things, and one of the main reasons I love the OS family, particularly OpenBSD.
__________________
dc -e '[q]sa[ln0=aln256%Pln256/snlbx]sb12247225403800449909543746snlbxq'
Reply With Quote
 

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
reinstall all packages installed by pkg_add mfaridi OpenBSD Packages and Ports 4 5th March 2015 12:47 PM
Delete or replace all installed packages shep OpenBSD Packages and Ports 3 24th May 2010 01:31 AM
Listing of installed packages cyril OpenBSD Packages and Ports 2 9th June 2009 01:24 AM
sorting special characters gosha Programming 15 9th April 2009 02:29 AM
Sorting Packages JMJ_coder NetBSD Package System (pkgsrc) 3 20th May 2008 01:08 AM


All times are GMT. The time now is 12:26 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick