假设我的输入文件myInput.txt
如下所示:
~~~ text1
bla bla
some more text
~~~ text2
lorem ipsum
~~~ othertext
the wikipedia
entry is not
up to date
也就是说,有文档以 . 分隔~~~
。所需的输出如下:
text1: bla bla some more text
text2: lorem ipsum
othertext: the wikipedia entry is not up to date
我该怎么做?以下似乎很不自然,而且我失去了标题:
val converter: Task[Unit] =
io.linesR("myInput.txt")
.split(line => line.startsWith("~~~"))
.intersperse(Vector("\nNew document: "))
.map(vec => vec.mkString(" "))
.pipe(text.utf8Encode)
.to(io.fileChunkW("flawedOutput.txt"))
.run
converter.run