Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm processing a text file that has a few statements of the form




or even


(the idiom '...' appears only in these structures) that I'd like to convert to statements of the form...

 '0' '1' '2' '3' '4' '5' '6' '7'

I can do this with vim marcos, reasonably cutely, or knock up some python, but I'd like to do it from the command line. Can I get a recommended starting point? I'm suspecting there's some sed magic that can be done but I can't get my head around it...

share|improve this question
up vote 3 down vote accepted

bash has a sequence operator that you can use:

sequence () { 
    read start finish <<< "${1/.../ }"
    eval echo {$start..$finish}
while read line; do
    sequence "$line"
done << END
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7 8 9
a b c d e f g h i j

I have to use eval because bash will attempt to expand the sequence before it expands the variables. See

share|improve this answer

Assuming the sequences are always ascending;

$ cat input alphabet

tr \'. '  ' <input  | 
while read f t ; do 
    grep -Po "$f.*?$t" alphabet;


This is probably a lot slower than the bash-eval version.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .