Как разделить токены в строке с помощью Unix ? показал, что файл может быть токенизирован с помощью sed
или xargs
.
Есть ли способ сделать обратное?
[in:]
some
sentences
are
like
this.
some
sentences
foo
bar
that
[выход]:
some sentences are like this.
some sentences foo bar that
Единственным разделителем в предложении является \n\n
. Я мог бы сделать следующее на python, но есть ли способ unix?
def per_section(it):
""" Read a file and yield sections using empty line as delimiter """
section = []
for line in it:
if line.strip('\n'):
section.append(line)
else:
yield ''.join(section)
section = []
# yield any remaining lines as a section too
if section:
yield ''.join(section)
print ["".join(i).replace("\n"," ") for i in per_section(codecs.open('outfile.txt','r','utf8'))]
[вышло:]
[u'some sentences are like this. ', u'some sentences foo bar that ']
.
? - person fedorqui 'SO stop harming'   schedule 14.02.2014