我有一个文本文件,其句子格式如下:
awk
我想知道是否有一种重新格式化文本的方式,所以基本上没有选项卡:
Blah blah blah
blah blah blah.
Another random sentence
that sentence continued.
或者:
Blah blah blah blah blah blah.
Another random sentence that sentence continued.
答案 0 :(得分:1)
以下是一些选项。如果您在问题中创建了文本文件,或者dput()
在阅读了文本文件后得到了什么,将会更加清楚您所面对的问题。
fileConn <- file("delete_me.txt")
writeLines(c("Blah blah blah",
"blah blah blah.",
"Another random sentence",
"that sentence continued."), fileConn)
close(fileConn)
text <- read.delim("delete_me.txt",
header=F)
text
V1 1 Blah blah blah 2 blah blah blah. 3 Another random sentence 4 that sentence continued.
paste(text$V1, collapse = " ")
[1] "Blah blah blah blah blah blah. Another random sentence that sentence continued."
如果您有任何问题,请告诉我。
text="Blah blah blah
blah blah blah.
Another random sentence
that sentence continued."
gsub("\n", " ", text)
"Blah blah blah blah blah blah. Another random sentence that sentence continued."
strsplit(gsub("\n", "", text), ".",fixed=T)
"Blah blah blahblah blah blah" "Another random sentencethat sentence continued"