Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I insert a new line after each character in shell script?

Assuming I have the following string:

abcdefghi

Which command can I use so that the outcome is:

a
b
c
d
e
f
g
h
i

I just started coding so I hope someone can help me.

like image 469
bogdan Avatar asked Oct 17 '25 16:10

bogdan


1 Answers

There is a tool called fold which inserts linebreaks, and you can tell it do add one after every character:

$ fold -w 1 <<< 'abcdefghi'
a
b
c
d
e
f
g
h
i

<<< is used to indicate a here string. If your shell doesn't support that, you can pipe to fold instead:

echo 'abcdefghi' | fold -w 1
like image 161
Benjamin W. Avatar answered Oct 19 '25 07:10

Benjamin W.