Jun 16

Some times, while scripting, you need to print a sequence of letters or numbers. Don’t write it yourself ! Bash it using seq or curly braces!

Some examples:

#seq 1 3

1
2
3

# seq -s : 1 10
1:2:3:4:5:6:7:8:9:10

# seq -s : 0 2 10
0:2:4:6:8:10

#echo {1..10}

1 2 3 4 5 6 7 8 9 10

# echo {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y z

Building some hash directories :

# mkdir -p test/{1..5}/{1..5}

 

written by MG \\ tags: ,


2 Responses to “Bash: How to print a sequence of letters or numbers”

  1. 1. Hoss Bear Says:

    # printf “%s ” {0..9} && printf “%s ” {a..z} && printf “%s ” {A..Z}
    0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

  2. 2. Hoss Bear Says:

    #echo `printf “%s ” {0..9} && printf “%s ” {A..F}` | awk ‘{ for (i = 1; i <= NF; i++)for (j = 1; j <= NF; j++)for (k = 1; k <= NF; k++)for (l = 1; l <= NF; l++) print $i $j $k $l}'

    ## this gives you all 4digit hexnumbers like squid is using them for its cache directories

Leave a Reply

*