Take the 2-minute tour ×

I want to extract just the first filename from a remote zip archive without downloading the entire zip. In particular, I'm trying to get the build number of dartium (link to zip file). Since the file is quite large, I don't want to download the entire thing.

If I download the entire thing, unzip -l reports the first file as being: 0 2013-04-07 12:18 dartium-lucid64-inc-21033.0/. I want to get just this filename so I can parse out the 21033 portion as the build number.

I was doing this (total hack):

curl -s $_url | head -c 256 | sed -n "s:.*dartium-lucid64-inc-\([0-9]\+\).*:\1:p"

It was working when I had my shell in ASCII mode, but I recently switched it to UTF-8 and it seems sed is now honoring that, which breaks my script.

I thought about hacking it by doing:

export LANG=
curl -s ...

But that seemed like an even bigger hack.

Is there a better way?

share|improve this question
That's a pretty cool solution to get information about the file list without downloading the entire thing, thanks! –  Martijn de Milliano Apr 7 '13 at 21:22
add comment

1 Answer

up vote 1 down vote accepted

Firstly, you can set bytes range using curl.

Next, use "strings" to extract all strings from binary stream.

Add "q" after "p" to quit after find only first occurrence.

curl -s $_url -r0-256 | strings | sed -n "s:.*dartium-lucid64-inc-\([0-9]\+\).*:\1:p;q"

Or this:

curl -s $_url -r0-256 | strings | sed -n "/dartium-lucid64/{s:.*-\([^-]\+\)\/.*:\1:p;q}"

It must be a bit faster and more reliable. Also it extracts full version, including subversion (if you need it).

share|improve this answer
+1 Just a touch less hacky than mine. –  tjameson Apr 7 '13 at 21:57
add comment

Your Answer


