Fehérke's GitHub Site == glue between Fehérke's GitHub hosted projects

seq.sh - embeded seq

Kind of embedded seq. Sometimes happens that you need a bunch of text lines with some periodically changing numeric values in them. Usually for download with wget. But sadly, with all it’s almost omnipotent parameters, using wget can be difficult if there is no index page with followable links or the thumbnails are messed between the full size pictures. So you will have to do more single-file downloads instead of one recursive. And you will use the -i switch and an input file. But how you can create that file easier ? Naturally, with a for and a seq :

Bash code - old, deprecated example

for i in `seq 10`; do wget http://example.com/public/file_$i.txt; done

Note
In meantime Bash’s brace expansion was significantly improved :

  • Bash 2.05 introduced brace expansion for series of values {a,b,c,d,e,f}
  • Bash 3.0 introduced sequence expansion for numbers {1..10} and letters {a..z}
  • Bash 4.0 introduced sequence increment {1..10..2} and zero padding {01..10}

Bash code - new, modern example

wget http://www.example.com/public/file_{1..10}.txt

Usage

seq.sh makes this easier. You just mark the expandable values and seq.sh will generate the list of strings. The marks are of form :

For more details see the man page.

So this file :

sample input

http://www.example.net/archive/{2003 2004}-{-w 3 3 12}.zip
http://www.example.com/gallery{2}/pamela_a_{#1}/{3}_{#2}.jpg

will be transformed into this :

sample output - seq.sh < input.txt

http://www.example.net/archive/2003-03.zip
http://www.example.net/archive/2003-06.zip
http://www.example.net/archive/2003-09.zip
http://www.example.net/archive/2003-12.zip
http://www.example.net/archive/2004-03.zip
http://www.example.net/archive/2004-06.zip
http://www.example.net/archive/2004-09.zip
http://www.example.net/archive/2004-12.zip
http://www.example.com/gallery1/pamela_a_1/1_1.jpg
http://www.example.com/gallery1/pamela_a_1/2_2.jpg
http://www.example.com/gallery1/pamela_a_1/3_3.jpg
http://www.example.com/gallery2/pamela_a_2/1_1.jpg
http://www.example.com/gallery2/pamela_a_2/2_2.jpg
http://www.example.com/gallery2/pamela_a_2/3_3.jpg

Configuration

None.

Not even command line parameters exist.

Versions

Plans

Download

You can find the related files on GitHub in my Bash-script repository’s seq directory :