skip to Main Content

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?

2

Answers


  1. 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.

    Login or Signup to reply.
  2. To replace all whitespace with newlines, try

    tr -s ' t' 'n' <file >newfile
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search