Relevance help, trying to parse from text file and concatenate name from each line

Hey everyone, looking for a little help on this. I am trying to parse a log file and pull out a few pieces of information, and create the computer name from those pieces. The first piece of relevance is pulling the site #, code directly below, and returns 0123, 0124,0125, and 0126

firsts 4 of following texts of firsts "CHG_" of (lines whose (it contains "CAR" and it contains ((month of it as two digits & "/" & day_of_month of it as two digits & "/" & year of it as string) of date (local time zone) of (now-1*day) as string) of date (local time zone) of (now-1*day)) of file "c:\log\Cardir.txt"

I then have another piece of relevance is pulling back the “p” or “b” from before the “.dat” on the end of the file, code below, and returns “p”,“b”,“b”.

lasts 1 of preceding texts of firsts ".dat" of (lines whose (it contains "CAR" and it contains ((month of it as two digits & "/" & day_of_month of it as two digits & "/" & year of it as string) of date (local time zone) of (now-1*day) as string) of date (local time zone) of (now-1*day)) of file "c:\CARdir.txt")

Lastly, I have a third relevance query to pull the files that end in .DAT, code below, and provides a single “DAT”

lasts 1 of preceding texts of firsts ".DAT" of (lines whose (it contains "CAR" and it contains ((month of it as two digits & "/" & day_of_month of it as two digits & "/" & year of it as string) of date (local time zone) of (now-1*day) as string) of date (local time zone) of (now-1*day)) of file "c:\log\CARdir.txt")

I am trying to create the value “PETER” if there is a “p” returned at the end of the line and “BOB” if there is a “b” at the end and concatenate first the site # with either PETER or BOB so that I can gather the device name, ie. 0123PETER

To throw icing on the cake, but if I cannot get this, we can do this manually, if the third query returns a "DAT"
An example of the actual file is below

03/08/2016 05:04 PM 48,997 CAR_0123_20160308_170439_p.dat
03/08/2016 05:04 PM 48,593 CAR_CHG_0124_20160308_170440_b.dat
03/08/2016 05:04 PM 49,098 CAR_CHG_0125_20160308_170438_b.dat
03/07/2016 05:06 PM 8,597 CAR_CHG_0126_20160307_170629.DAT

I was trying to get the first piece by using the below, which gives a singular expression, which I understand, but cannot figure out how to do it properly.

if (lasts 1 of preceding texts of firsts ".dat" of (lines whose (it contains "CAR" and it contains ((month of it as two digits & "/" & day_of_month of it as two digits & "/" & year of it as string) of date (local time zone) of (now-1*day) as string) of date (local time zone) of (now-1*day)) of file "c:\log\CARdir.txt") = p) then "PETER" else "BOB"

Any help is appreciated :slight_smile: String parsing makes me sad.

So what is the final output you are ultimately looking to get?

do the following construction, if in second case really read another file not from “log” folder (if it is overlook and the same .txt used for all 3 relevances, it could be simplified):

(item 0 of it & item 2 of it) of
(item 0 of it, item 1 of it, (if (item 2 of it = "p") then "PETER" else "BOB") of it) of 
(_relevance_1_returns_string_, _relevance_2_returns_string_, _relevance_3_returns_string_) 

p.s. if everywhere file is "c:\log\Cardir.txt"
then it could be + somewhere file existing condition becuase it will fail in case of its absence
p.s. singular items used

(item 0 of it & item 2 of it) of
(item 0 of it, item 1 of it, (if (item 2 of it = "p") then "PETER" else "BOB") of it) of 
(first 4 of following text of first "CHG_" of it as string | "", last 1 of preceding text of first ".dat" of it | "", last 1 of preceding text of first ".DAT" of it | "") of 
(lines whose (it contains "CAR" and it contains ((month of it as two digits & "/" & day_of_month of it as two digits & "/" & year of it as string) of date (local time zone) of (now-1*day) as string) of date (local time zone) of (now-1*day)) of file "c:\log\CARdir.txt")
1 Like

Hey VitaliL, this is very close, I appreciate your help! I mistyped above when I asked for “0123PETER and 0124BOB”. I actually need that reversed. ie. PETER0123 and BOB0124

Also, if there is a .DAT extension in the file, I need the site number to return both the PETER0123 and BOB0123 for that particular site. Basically, if the extension has a “.dat” extension, it means that the CAR file has already been split for a particular type of server. With the “.DAT” extension, it means that it has not been split and needs to be copied and renamed to PETER0123 and BOB0123 for the same site. It is always going to be the same txt file as well. I will work on what you have provided and try to figure it out.

I would not have come up with this in 100 years, much appreciated, thank you.

-Jesse

Try this:

(it, (item 1 of it & item 0 of it) of (preceding text of first "_" of it, (if (it ends with "p.dat") then "PETER" else if (it ends with "b.dat") then "BOB" else ("PETER";"BOB"))of it) of (following text of first "CHG_" of it | it) of following text of first "CAR_" of it) of lines whose(it contains "CAR_") of files "c:\log\CARdir.txt"

Where are the file names that are in CARdir.txt coming from? If it is a folder on the same system, then you could just query the file names directly rather than having to query CARdir.txt, which would actually be easier to do with relevance.


This will give you the newest date in the CARdir.txt file:

(year of it as string & month of it as two digits & day_of_month of it as two digits) of (maximum of (it as date) of (last 2 of it & " " & (substring (4,2) of it as integer as month as three letters) & " " & first 4 of it) of (preceding text of first "_" of following text of first "_" of (following text of first "CHG_" of it | it) of following text of first "_" of it) of lines whose(it contains "CAR_") of files "c:\log\CARdir.txt")

It converts the YYYYMMDD strings into dates, then gets the maximum, then turns it back into a YYYYMMDD string for comparison with the lines of the file.

1 Like

Hey @jgstew, not sure why I thought I had to output the to a text file, then parse from that. I just tested a few things, and that endpoint that the analysis was running on DOES have direct access to the folder where the files reside, let’s call it c:\CARstaging.

Either way, I was able to use what you provided to get this going, very awesome. Thanks to you both! This will save me at least 10 minutes every morning and make other happy as well. I may look into pulling this from the folder itself next time, instead of from the text file that contains the output.

1 Like

Try this to get the newest set of files in CARstaging directly:

items 1 of (it, files of folders "c:\CARstaging") whose(item 1 of it contains item 0 of it) of (year of it as string & month of it as two digits & day_of_month of it as two digits) of (date (local time zone) of it) of maximum of modification times of files of folders "c:\CARstaging"

Hey @jgstew , The above relevance gives me a type error "the operator “contains” is not defined for the types ’ contains ’ Any more guidance would be appreciated, thank you