how could in bash a pattern like

ROW1   n1    n2    n3   n4 

up to 300 be done with some command in bash or also just perl...the delimiter would need to be \t

as above


You can use brace expansion and printf:

printf "%s\t" ROW1 n{1..300}

The first string specifies the format of output to printf, and %s is replaced with a corresponding argument. Since there is only %s, printf will re-use the format specifier until all arguments are exhausted. This will leave a trailing tab.

{1..300} is bash syntax which expands into numbers from 1 to 300, separated by spaces. If a string is added before or after the braces, the expanded form will also have that string attached.

To avoid a trailing tab, you'll have to print something separately, either the first word, or the last:

printf "ROW1"; printf "\tn%d" {1..300}
printf "%s\t" ROW1 n{1..299}; echo n300

Simpler command:

echo -n "ROW1" && echo -ne "\t"n{1..300}

Even simpler thanks to @hildred

echo -ne "ROW1" "\t"n{1..300}
  • 3
    even simpler: echo -ne "ROW1" "\t"n{1..300}
    – hildred
    Jun 25 '15 at 17:29

In a one-liner:

echo -n "ROW1"; for ((i=1; i<=300; i++)); do echo -ne "\t n${i}"; done

Or using the same approach using brace expansion (thanks to A.B. for the suggestion):

echo -n "ROW1"; for i in {1..300}; do echo -ne "\t n${i}"; done
  • 1
    echo -n "ROW1"; for n in {1..300}; do echo -ne "\t n$n"; done ;)
    – A.B.
    Jun 25 '15 at 19:36

Because you mentioned perl

perl -e 'printf "ROW1"; printf "\tn%d",$_ foreach (1..300)'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.