# Ubuntu – Bash create custom string

bashformatperlregex

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