我设法从3个不同的.txt文件中获取这些行 . 我使用“grep”命令来提取包含单词“Boiling”的行 . 但是我只想要这个值(见结果) . 那么如何使用grep命令提取空字符串后的所有值,并仅将这些值保存在csv / excel文件中
[1] " Boiling: 80 - 93 °C (176°F - 199.4 °"
[1] " Boiling: > 93.3 °C (> 199.94 °F) "
[1] " Boiling: 80 - 93 °C (176° closed cup"
结果应如下(删除引号):
80 - 93 °C (176°F - 199.4 °
> 93.3 °C (> 199.94 °F)
80 - 93 °C (176° closed cup
以下是我的代码
my_txt<-list.files("G:\\FlashPointTest\\Test2\\sdstotextorigin",
pattern = ".txt$",full.names = TRUE,recursive = FALSE )
lst<-vector("list",length(my_txt))
names(lst)<-my_txt
for(i in 1:length(my_txt)){
doc<-readLines(my_txt[i])
doc<-doc[grepl("Boiling",doc)]
lst[[my_txt[[i]]]]<-doc
}
非常感谢你的帮助!
2 回答
这里有很多方法:(尝试使用完整数据做得最好)
数据:
1:
2:
3:
用vec作为安德烈的回答: