开发者

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 becom开发者_如何学Pythone

  sdf
  sdfsd= 
  sdfsdf 
  sdfsdf

thanks


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.


enter the following command:

:%s/ /\r/g

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


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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜