Hey everyone,? ? I have been having an issue trying to find a specific string of text in a log of system messages. ?I have tried to use pmatch, match, and some regular expressions but all to no avail. ? I have a matrix / data.frame (either one, the file outputs a tens of thousands of rows with a single column) of strings in the following format with different items after INFO: ?"09:11:57.259 - Assay File Processing Thread - INFO - SolenoidCycleMessage: Addr = 0x03 " as an example I would like to match "SolenoidCycleMessage" searchString<-"SolenoidCycleMessage" matchString<-"09:11:57.259 - Assay File Processing Thread - INFO - SolenoidCycleMessage: Addr = 0x03"> pmatch(searchString, matchString)[1] NA> match(searchString, matchString)[1] NA> match(matchString, searchString)[1] NA> grep(searchString, matchString, ignore.case=FALSE)[1] 1> df<-as.data.frame(c(matchString, string1, string2)) > df? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?c(matchString, string1, string2) 1 09:11:57.259 - Assay File Processing Thread - INFO - SolenoidCycleMessage: Addr = 0x03? 2 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?23:12:43.22 - Test 3 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?test> grep(searchString, df, ignore.case=FALSE)integer(0)> grep(searchString, c(matchString, string1, string2), ignore.case=FALSE)[1] 1 Doe anyone have some input that could help? Thanks,? Kevin
Hi Kevin, It's not totally clear to me what the desired output is. grep(searchString, matchString, ignore.case=FALSE) told you that searchString is in the first element of matchString. Isn't that what you want to know? If not, perhaps you can be more specific about what the desired result is. Best, Ista On Wed, Aug 12, 2015 at 11:51 AM, Kevin Kowitski <k.kowitski at icloud.com> wrote:> Hey everyone, > > I have been having an issue trying to find a specific string of text in a > log of system messages. I have tried to use pmatch, match, and some regular > expressions but all to no avail. > > I have a matrix / data.frame (either one, the file outputs a tens of > thousands of rows with a single column) of strings in the following format > with different items after INFO: > "09:11:57.259 - Assay File Processing Thread - INFO - SolenoidCycleMessage: > Addr = 0x03 " > > as an example I would like to match "SolenoidCycleMessage" > searchString<-"SolenoidCycleMessage" > matchString<-"09:11:57.259 - Assay File Processing Thread - INFO - > SolenoidCycleMessage: Addr = 0x03" > >> pmatch(searchString, matchString) > > [1] NA > >> match(searchString, matchString) > > [1] NA >> >> match(matchString, searchString) > > [1] NA >> >> grep(searchString, matchString, ignore.case=FALSE) > > [1] 1 >> >> df<-as.data.frame(c(matchString, string1, string2)) >> df > > c(matchString, > string1, string2) > 1 09:11:57.259 - Assay File Processing Thread - INFO - SolenoidCycleMessage: > Addr = 0x03 > 2 > 23:12:43.22 - Test > 3 > test >> >> grep(searchString, df, ignore.case=FALSE) > > integer(0) > >> grep(searchString, c(matchString, string1, string2), ignore.case=FALSE) > > [1] 1 > > Doe anyone have some input that could help? > > Thanks, > Kevin > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
I haven't tested this, but what about: df <- data.frame(mtch=c(matchString, string1, string2)) grep(searchString, df$mtch, ignore.case=FALSE) Depending on what your next step is, you might prefer grepl. Sometimes using fixed=TRUE in grep() helps. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 8/12/15, 8:51 AM, "R-help on behalf of Kevin Kowitski" <r-help-bounces at r-project.org on behalf of k.kowitski at icloud.com> wrote:>>df<-as.data.frame(c(matchString, string1, string2)) >>df > c(matchString, >string1, string2) >1 09:11:57.259 - Assay File Processing Thread - INFO - >SolenoidCycleMessage: Addr = 0x03 >2 >23:12:43.22 - Test >3 > test >>grep(searchString, df, ignore.case=FALSE) >i