Bash script: split word on each letter

command linesplitwords

How can I split a word's letters, with each letter in a separate line?

For example, given "StackOver"
I would like to see

S
t
a
c
k
O
v
e
r

I'm new to bash so I have no clue where to start.

Best Answer

I would use grep:

$ grep -o . <<<"StackOver"
S
t
a
c
k
O
v
e
r

or sed:

$ sed 's/./&\n/g' <<<"StackOver"
S
t
a
c
k
O
v
e
r

And if empty space at the end is an issue:

sed 's/\B/&\n/g' <<<"StackOver"

All of that assuming GNU/Linux.

Related Question