Question

I want to get this string -> Example example1

in this form:

E  
x  
a  
m  
p  
l  
e

e  
x  
a  
m  
p  
l  
e  
1  
Was it helpful?

Solution

Use fold utility with width=1:

echo 'Example example1' | fold -w1
E
x
a
m
p
l
e

e
x
a
m
p
l
e
1

Another option is grep -o:

echo 'Example example1' | grep -o .
E
x
a
m
p
l
e

e
x
a
m
p
l
e
1

OTHER TIPS

Using standard unix tools, you can do, for example:

echo "Example example1" | sed 's/\(.\)/\1\n/g'

Using pure bash:

echo "Example example1" | while read -r -n 1 c ; do echo "$c"; done

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top