[FIXED] Edit format of text file in Linux Terminal

Issue

I have this text file :

z1 x2 c3 v4 b5 n6 m7 a8

and i want to reformat it to:

z1
x2
c3
v4
b5
n6
m7
a8

in the Linux Terminal .
How can I do this?

Solution

Replace spaces with newlines using sed

sed 's/ /\n/g' my_file > my_file_reformatted

You can find the syntax of sed on the manual page, but essentially you put the character string you want to replace between the first pair of /, and the string to replace it with between the second one.

You also don’t nessesarily need to use / as the delimiter, it could be any other character.

Answered By – silentsky

Answer Checked By – Gilberto Lyons (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published