Fun With Bash

Discussion in 'NZ Computing' started by Lawrence D'Oliveiro, Jan 23, 2010.

  1. I found an interesting collection of files in the directory
    /usr/lib/openoffice/basis3.1/presets/config on my system. This includes
    standard colour sets, marker styles, hatches, and a bunch of other presets
    for OpenOffice.org. In particular, the file standard.sob contains a set of
    standard brush images. I’m sure you can view these from within OOo itself,
    but where’s the fun in that? :)

    Turns out most of these are text files—in fact, XML files that you can view
    and make some sense of directly. But standard.sob is a binary file. In fact,
    it’s a ZIP archive. Listing its contents reveals the following:

    ldo@theon:config> unzip -l standard.sob
    Archive: standard.sob
    Length Date Time Name
    --------- ---------- ----- ----
    3649 2008-05-11 13:25 Content.xml
    2866 2008-05-11 13:32 META-INF/manifest.xml
    0 2002-07-26 10:20 mimetype
    69 2008-05-11 00:44 Pictures/100000000000000800000008DD0ADA29.png
    4073 2008-05-11 00:44 Pictures/100000000000005E0000005E1A713443.png
    8863 2008-05-11 00:44 Pictures/100000000000005E0000005E1E2E908A.png
    (etc)

    So the brush images look like straight PNG images. How to browse through
    these? Sure, I could extract them all to a temporary directory, but that
    means creating temporary files I’d have to remember to delete afterwards.
    Can I just extract them and view them on the fly?

    Yes, it turns out the unzip command has a “-p†option, which means the file
    contents are extracted to standard output, rather than a named file. So in
    Bash, I could use the “display†command from ImageMagick to display a single
    image like this:

    display <(unzip -p standard.sob Pictures/100000000000000800000008DD0ADA29.png)

    But how to get all the files listed like this on one command line? First of
    all, extract just the names of the PNG files from the ZIP archive listing:

    unzip -l standard.sob | perl -lne '/(\S+\.png)/ && print $1;'

    produces output like

    Pictures/100000000000000800000008DD0ADA29.png
    Pictures/100000000000005E0000005E1A713443.png
    Pictures/100000000000005E0000005E1E2E908A.png
    (etc)

    So the final command I came up with was

    eval display $(for f in $(unzip -l standard.sob | perl -lne '/(\S+\.png)/ && print $1;'); do echo "<(unzip -p standard.sob $f)"; done)

    Exercise for the reader: why do I need that “eval†on the front?
    Lawrence D'Oliveiro, Jan 23, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken Briscoe
    Replies:
    0
    Views:
    433
    Ken Briscoe
    Jul 14, 2004
  2. Replies:
    3
    Views:
    650
  3. Luke

    Fun fun fun

    Luke, Oct 7, 2003, in forum: Computer Support
    Replies:
    3
    Views:
    561
    Petit Alexi
    Oct 7, 2003
  4. Consultant

    OT Thursday, uh, fun, yeah, fun!

    Consultant, Feb 8, 2007, in forum: MCSE
    Replies:
    17
    Views:
    639
    TechGeekPro
    Feb 10, 2007
  5. Replies:
    0
    Views:
    256
Loading...

Share This Page