[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] bash suitable for parsing big files?

From: Greg Wooledge
Subject: Re: [Help-bash] bash suitable for parsing big files?
Date: Fri, 13 Sep 2013 08:11:33 -0400
User-agent: Mutt/

On Fri, Sep 13, 2013 at 02:55:36AM +0000, adrelanos wrote:
> The script I am writing looks what files are installed, downloads the
> package from $linux-distribution's repositories and compares them with
> the ones on the disk.

On Fri, Sep 13, 2013 at 12:05:25AM +0000, adrelanos wrote:
> For those who don't know /var/lib/dpkg/status, it's size is roughly 2 MB
> and contains roughly 50.000 lines.

Ugh.  Parsing /var/lib/dpkg/status is not the best approach at all.

while read -r pkg _; do
  ... process "$pkg" somehow ...
done < <(dpkg --get-selections)

>From the man page:

       --get-selections [package-name-pattern...]
              Get  list of package selections, and write it to stdout. Without
              a pattern, non-installed packages (i.e. those  which  have  been
              previously purged) will not be shown.

This saves you from having to write a finite state machine sort of thing
to parse the multiple-lines-per-package status file (which you would have
to do in order to filter out the non-installed ones).

reply via email to

[Prev in Thread] Current Thread [Next in Thread]