r - R在以“***”开头的文件中查找字符串
问题描述
我有一个文件,其中包含以“***”开头的特定行,因为它以通配符开头,如何找到该字符串的行?
我通常会使用
Line_n <- grep("*** The Maximum 1hour", readLines(con=filename))
谢谢!
解决方案
s <- c("** The Maximum 1hour", "*** The Maximum 1hour",
"*** The Maximum 2hours", "The Maximum 1hour",
"*** The Maximum 1hour", "+++ The Maximum 1hour",
"dummy *** The Maximum 1hour")
grep("^[*]{3} The Maximum 1hour", s)
[1] 2 5
查找字符串开头正好有 3 个星号的字符串(但仅在那时)。