Is there any function in any package that can read a text file with regex and return string numbers of found matches. Like gsubfn read.pattern can find and extract a pattern but can't return line number and grep can't read files directly. Example:
file:
.122448110000D+06 .400000000000D+01
3 15 3 23 10 0 0.0 .267305411398D-03 .161435309564D-10 .000000000000D+01
.510000000000D+02 .625000000000D-01 .440982654411D-08 .306376855997D+00
5 15 3 23 11 59 44.0 -.263226218521D-03 .488853402202D-11 .000000000000D+01
pattern: reg="^ *\\d+ +(?:[0-9]+ +){5}[.0-9]+.*$"
for 2nd and 4th line match. So what I generally want is:
>file.grep(file,reg)
[1] 2 4
Is there anything of sorts? I get the general philosophy when dealing with such things is readLines
and then getting creative with grep
which is fine when files are not that big. But I read here many people having problems with large and not table-structured data sets, things that could be solved with such tool (or with readLines
supporting regex skip
parameter) and I wonder if anyone made something like that.