【发布时间】:2014-02-14 20:25:15
【问题描述】:
如何使用 Unix 分隔标记?
[输入]:
some sentences are like this.
some sentences foo bar that
[输出:]
some
sentences
are
like
this.
some
sentences
foo
bar
that
我本可以在 python 中做到这一点,但有没有任何 unix 方法可以实现相同的输出?
>>> 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
【问题讨论】: