This question already has an answer here:
- How split a file in words in unix command line? 11 answers
How to separate tokens in line using Unix?
[in]:
some sentences are like this.
some sentences foo bar that
[out:]
some
sentences
are
like
this.
some
sentences
foo
bar
that
I could have done this in python as below, but is there any unix way to achieve the same output?
>>> import codecs
>>> outfile = codecs.open('outfile.txt','w','utf8')
>>> intext = "some sentences are like this.\n some sentences foo bar that"
>>> infile = codecs.open('infile.txt','w','utf8')
>>> print>>infile, intext
>>> for i in codecs.open('infile.txt','r','utf8'):
... for j in i.split():
... print>>outfile, j
... print>>outfile
...
>>> exit()
alvas@ubi:~$ cat outfile.txt
some
sentences
are
like
this.
some
sentences
foo
bar
that