[Noisebridge-discuss] brace expansion tricks [was Re: city of oakland internal emails dump on DocumentCloud]

Leif Ryge leif at synthesize.us
Tue Mar 6 01:25:42 PST 2012


On 03/05/2012 06:03 PM, Flatline wrote:
> Also, in PDF form, easier for human eyes to parse:
> http://s3.documentcloud.org/documents/320449/oakland-city-official-emails-10-11-2011-to-11-13.pdf
>
> On 03/05/2012 05:58 PM, Flatline wrote:
>> Or here it all is in one handy text file:
>> http://s3.documentcloud.org/documents/320449/oakland-city-official-emails-10-11-2011-to-11-13.txt

Much better than a bunch of gifs!

>> On 03/05/2012 02:35 PM, Nicholas Granado wrote:
>>> you can run the following code to download them all ....
[snip]
>>> def main():
>>> for i in range(1, 2184):
>>> url =
>>> "http://s3.documentcloud.org/documents/320449/pages/oakland-city-official-emails-10-11-2011-to-11-13-p%d-normal.gif"
>>> % (i)
>>> download_image_url(url)

If you did want to download all those gifs, you needn't write a script 
to do it... you could just use curl's [] sequence feature:
curl -O 
http://s3.documentcloud.org/documents/320449/pages/oakland-city-official-emails-10-11-2011-to-11-13-p[1-2184]-normal.gif

Or, if you wanted to use wget or something else, you could also use the 
bash shell's brace expansion feature to turn {1..2184} into that many 
separate arguments. If you aren't familiar with brace expansion, check 
out these other examples of it:
echo {a{3..1},b{5,6},c{009..10}}  # echoes a3 a2 a1 b5 b6 c009 c010
echo {a..z}{a..z}{a..z}  # echoes all 17576 possible 3-letter words
cp /path/foo{,.backup}   # copies /path/foo to /path/foo.backup

See the bash manual (man bash) if you want to know more.

~leif


More information about the Noisebridge-discuss mailing list