[zsh] zsh で連番生成、ただしN個おき
例えばファイル名の一部として使うと行った目的で番号を連番生成する場合、zsh であれば
file_{0..3}.txt
とすれば
file_0.txt file_1.txt file_2.txt file_3.txt
と展開してくれる。
では、これが連続した番号ではなく、一定間隔の番号、例えば
file_0.txt file_3.txt file_6.txt file_9.txt
という並びを作るにはどうしたらいいんだろう?
探してみたらありました。さすが zsh。
% echo file_{0..9..3}.txt
file_0.txt file_3.txt file_6.txt file_9.txt
以下、zshマニュアルの 14.6 Brase Expansion から抜粋:
An expression of the form ‘{n1..n2..n3}’, where n1, n2, and n3 are integers, is expanded as above, but only every n3th number starting from n1 is output. If n3 is negative the numbers are output in reverse order, this is slightly different from simply swapping n1 and n2 in the case that the step n3 doesn’t evenly divide the range. Zero padding can be specified in any of the three numbers, specifying it in the third can be useful to pad for example ‘{-99..100..01}’ which is not possible to specify by putting a 0 on either of the first two numbers (i.e. pad to two characters).
やっぱり zsh すごいな。
これでデータ処理がちょっと楽になるかな。
2014-05-24 06:00
nice!(0)
コメント(0)
トラックバック(0)
コメント 0