Unable to echo a-z in two columns by Zsh

I need to print the following sequence for illustration purposes in two columns

a-z

which has alphabets from a to z such that they are in 13-character columns.

How can you echo the characters from a to z into two columns?

Upvotes: 1

Views: 1029

Answers (3)

hlovdal
hlovdal

Reputation: 28228

Your question did not specify how to distribute the characters in the two coloumns, so here is an alternative answer:

prompt> paste <(echo "abcdefghijklm" | sed 's/\(.\)/\1\n/g' ) <(echo "nopqrstuvwxyz" | sed 's/\(.\)/\1\n/g')
a       n
b       o
c       p
d       q
e       r
f       s
g       t
h       u
i       v
j       w
k       x
l       y
m       z

prompt>

Upvotes: 0

nik
nik

Reputation: 13470

Very nice Stephan,

How about avoiding to type a through z with a loop?

for i in {a..z}; do echo -n $i; done | sed -e 's/\(.\)\(.\)/\1 \2\n/g'

Upvotes: 3

Stephan202
Stephan202

Reputation: 61559

Better solutions exist, I'm sure, but I'll give it a shot:

$ echo "abcdefghijklmnopqrstuvwxyz" | sed -e 's/\(.\)\(.\)/\1 \2\n/g'
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

Upvotes: 2

Related Questions