vehomzzz
vehomzzz

Reputation: 44578

Convert file one word per line

I would like to convert a text file containing words, space separate to a file where each word appears on a separate line

 sdf sdfsd= sdfsdf 
sdfsdf

will become

  sdf
  sdfsd= 
  sdfsdf 
  sdfsdf

thanks

Upvotes: 2

Views: 3962

Answers (4)

ghostdog74
ghostdog74

Reputation: 342373

$ tr " " "\n"<file|sed -n '/^$/!p'
sdf
sdfsd=
sdfsdf
sdfsdf

Upvotes: 1

too much php
too much php

Reputation: 91028

This is also easy to write as a shell script, you don't need sed or awk:

bash$ for word in $(cat input.txt); do echo "$word" >> output.txt; done

Upvotes: 1

Stephen
Stephen

Reputation: 49156

Try this:

:%s/\s\+/\r/g

Explained:

:%     // whole file
 s     // substitute
 \s\+  // some number of whitespace characters
 \r    // for carriage return

Thanks to @Dummy00001 for the + idea.

Upvotes: 6

coffeepac
coffeepac

Reputation: 634

enter the following command:

:%s/ /\r/g

or whatever the carriage return is for your environment. \r for *nix, \n for windows.

Upvotes: 1

Related Questions