Search code examples
bashsequenceseq

how to create a list of words using seq in bash


I am using seq -s " " -f " data%g :" 5 to create

data1 : data2 : data3 : data4 : data 5 : 

However, I want it to start a number of my choice instead of 1 and not to have ":" symbol at the very end. For example something like this:

data3 : data4 : data5

Is there any one-line solution for this?

Thanks in advance!

Current output:

seq -s " " -f " data%g :" 5
data1 : data2 : data3 : data4 : data 5 :

Desired:

data3 : data4 : data5

Solution

  • Use the following approach:

    start=3; seq -s" : " -f "data%g" $start 5
    

    The output:

    data3 : data4 : data5
    

    start=3 - custom variable that contains starting index

    -s" : " - item separator

    $start 5 - represents the range of the sequence. In our case: from 3 to 5