Return data once when the same data is present multiple times in a log file

(imported topic written by JoshMrtin9)

I am trying to pull out serial numbers for pos retail machines we have out in the field. Currently i can find one log file that contains this serial number, and it is written to when a trasaction is made. I have created an action script which runs a batch file on the pc to create a new directory with a copy of the log file which is being renamed so that i can run my relevance against the file to obtain the serial number. The reason for me taking this route is due to the file being busy a great deal of the time. So by making the copy i eliminated the factor of the file being busy while trying to run my relevance statement. Here is my current relevance that works and returns the serial number with no issue when only one serial number is present in the file.

if exists file 'C:\das\CLIENT\JM\textfile.log" whose (exists(line of it) whose (it contains “length=9”)) then (following texts of first “data=” of lines whose (it contains “length=9”) of files “C:\das\CLIENT\JM\textfile.log”) else “No S/N Available”

When more than one serial number is found i get the following error.

E: Singular Expression regers to non-unique object.

Can someone point me in the right direction here. I’m very close to this working, but can’t seem to wrap my head around how to only return one value if it exists more than once in the file.

(imported comment written by martinc)

If you could provide a sample of the file, it might be easier. I created the following relevance based on the file containing these couple lines

length=9

data=12345

length=9

data=123456

q: following text of first “=” of preceding text of first “;” of following texts of first “length=9;” of concatenation “;” of lines of file “c:\data\file.txt”

Not sure of that is what you need or not. I just did this quickly, so it may not be the “best” :slight_smile:

(imported comment written by JoshMrtin9)

Here is an example of what the file would look like to give you a better idea. Not all files will contain duplicates of the serial number im trying to receive, but it is possible and that was giving me the error i refered to earlier.

06/19/13 08:30:31.093:*** New log file C:\DAS\CLIENT\textfile.log *** Version 3.0.2.1771 (C:\DAS\CLIENT\textfile.log)

06/19/13 08:30:31.093:Open_Client: Open in Normal Transaction mode

06/19/13 08:30:31.093:thrConnectServer: Starting

06/19/13 08:30:31.093:*** Error (0): The operation completed successfully

06/19/13 08:30:31.093:thrConnectServer: CoInitializeEx failed (Continuing…)

06/19/13 08:30:31.093:ConnectServer: Attempting connect with Server xxxxxxxxx

06/19/13 08:30:31.093:ConnectServer: Try to get an Auth handle on xxxxxxxx via xxxxxxxxxxxx

06/19/13 08:30:31.140:ConnectServer: Time to Connect to xxxxxxxxxxxxxxxwas 0 seconds

06/19/13 08:30:31.390:ConnectServer: Server xxxxxxxxxx connected

06/19/13 08:30:31.390:thrConnectServer: Exiting

06/19/13 08:30:31.390:…LogLevel = 12

06/19/13 08:30:31.390:ReqAuthObject starts… AuthType: 0

06/19/13 08:30:31.390:ReqAuthObject: Request auth object from server…

06/19/13 08:30:31.640:ReqAuthObject: ReqAuthObject OK

06/19/13 08:30:31.640:SetAuthField: FID=262: length=1 data=0

06/19/13 08:30:31.640:SetAuthField: FID=288: length=1 data=N

06/19/13 08:30:31.640:SetAuthField: FID=289: length=6 data=SETTLE

06/19/13 08:30:31.640:SetAuthField: FID=370: length=11 data=00000000000

06/19/13 08:30:31.671:SetAuthField: FID=882: length=16 data=0000000000000000

06/19/13 08:30:31.671:SetAuthField: FID=888: length=9 data=123456789

06/19/13 08:30:31.671:SetAuthField: FID=889: length=5 data=xxxxxxxx

06/19/13 08:30:31.671:SetAuthField: FID=890: length=20 data=xxxxxxxxxxxxxx

06/19/13 08:30:31.671:SetAuthField: FID=893: length=64 data=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

06/19/13 08:30:31.734:SubmitAuth: SubmitAuth started…

06/19/13 08:30:31.843:thrTransactionTimer: Transaction started, will timeout in 180 seconds

06/19/13 08:30:32.343:SubmitAuth: SubmitAuthObj… AuthType 0

06/19/13 08:30:32.843:SubmitAuth: SubmitAuthObj succeeded

06/19/13 08:30:34.593:ParseAuthResp: Number of FIDs returned = 6

06/19/13 08:30:34.593:ParseAuthResp: FID=788, length=1, data=N

06/19/13 08:30:34.593:ParseAuthResp: FID=85, length=1, data=0

06/19/13 08:30:34.593:ParseAuthResp: FID=32, length=2, data=2106/19/13 08:30:34.593:ParseAuthResp: FID=33, length=20, data=Settlement Scheduled

06/19/13 08:30:34.593:ParseAuthResp: FID=0, length=3, data=999

06/19/13 08:30:34.593:ParseAuthResp: FID=1, length=11, data=No Response

06/19/13 08:30:34.593:thrTransactionTimer: Transaction completed

06/19/13 08:30:34.703:GetAuthField: FID: 788, Min: 0, Max: 1, Type: 201, Len: 1, data: N

06/19/13 08:30:34.703:GetAuthField: FID: 85, Min: 0, Max: 1, Type: 202, Len: 1, data: 0

06/19/13 08:30:34.703:GetAuthField: FID: 32, Min: 0, Max: 2, Type: 202, Len: 2, data: 21

06/19/13 08:30:34.703:GetAuthField: FID: 33, Min: 0, Max: 20, Type: 212, Len: 20, data: Settlement Scheduled

06/19/13 08:30:34.703:GetAuthField: FID: 0, Min: 1, Max: 5, Type: 1, Len: 3, data: 999

06/19/13 08:30:34.703:GetAuthField: FID: 1, Min: 2, Max: 100, Type: 2, Len: 11, data: No Response

06/19/13 08:30:34.703:Close_Client

06/19/13 08:30:34.953:Close_Client Completed.

(imported comment written by martinc)

Ok how about this:

q: following texts of firsts “length=9 data=” of lines whose (it as string contains "length=9 ") of file “c:\data\file.txt”

A: 123456789

I then added another line to the end of the file with the entry “06/19/13 08:30:31.671:SetAuthField: FID=888: length=9 data=1234567891” and the query returned:

q: following texts of firsts “length=9 data=” of lines whose (it as string contains "length=9 ") of file “c:\data\file.txt”

A: 123456789

A: 1234567891

notice the “texts of firsts”, this will allow for multiple return values if there are many lines with the “length=9”.

(imported comment written by JoshMrtin9)

Well the problem i am having is that “multiple” results i am getting are itenditcal. So what happens is when the device attempts to write to the log it records the same serial number over and over. So how can i only return the serial number once without getting the error Singular Expression regers to non-unique object.

(imported comment written by martinc)

How about:

q: unique values of following texts of firsts “length=9 data=” of lines whose (it as string contains "length=9 ") of file “c:\data\file.txt”

We will get there :slight_smile:

Martin

(imported comment written by JoshMrtin9)

Tried this to see if it would work and had it run over the night to see what i captured before i saw your most recent reply.

if

exists

file

“C:\das\CLIENT\JM\textfile.log”

whose
(
exists
(line

of

it
)

whose
(
it

contains

“length=9”
))

then
(following texts

of

first

“length=9 data=”

of

lines

whose
(
it

contains

“SetAuthField:”
)

of

files

“C:\das\CLIENT\JM\textfile.log”
)

else

“No S/N Available”

This was able to return around %90 of all the s/n’s, but i still got errors of “singular expression refers to non-unique object.”

I am currently running your example and will have results shortly =]

(imported comment written by Tim.Rice)

What happens if you use the Singular word LINE rather than LINES?