Brian Dunning's FileMaker Custom Functions

filterLines ( filterField ; filterValue ; Result )

Examines a list of values, removing lines that do not contain a given filter value.

  Average rating: 4.6 (29 votes) Log in to vote

Rob Atkinson   Rob Atkinson
Webwyz Systems
http://www.webwyzsystems.com

Share on Facebook Share on Twitter

  Sample input:
filterLines(
"Joe Smith BC 95
Fred Jones AB 96
Gail Peters NB 98
Herb Gardner SK 95";
"95";
"")
  Sample output:
Joe Smith BC 95
Herb Gardner SK 95

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

Many solutions have a field where a log is written line by line - for revisions, modifications, etc. Usually a carriage return is used to separate each line.
As the system ages, records can end up with a single field containing hundreds of log entries - detailing a wide variety of information.
Use filterLines to recursively search a text field, line by line for a given value. Only lines containing that value is returned.
Each line must be separated by a carriage return(ΒΆ).

 

Comments

Bruce Robertson   Bruce Robertson
Jan 14, 2012
Can also be written as:

/*
filterLines( filterField; filterValue )
*/

Case( IsEmpty( filterField );"" ;

Let ([
numValues = ValueCount( filterField );
topValue=LeftValues ( filterField; 1 );
match=Case(PatternCount(topValue; filterValue); topValue);
remainValues=RightValues( filterField; numValues-1)];

match & filterLines( remainValues; filterValue)
)
)
 
Rob Atkinson   Rob Atkinson, Vancouver
Jan 15, 2012
Thanks Bruce! Much neater and more concise.
 
Derek Bastille   Derek Bastille, University of Alaska Fairbanks
Jan 17, 2012
If you have a really long log, you might run into the recursion limits doing this (10,000). Thus, it might be better to take a page from the Unix grep utility and do this line by line. That is, use a script to:

-- put the lines in a variable
- iterate through the lines
- for each line, if a match copy the line to an output variable
- return the output variable
 
Rob Atkinson   Rob Atkinson, Vancouver, B.C.
Jan 18, 2012
You are right Derek - I should have pointed this out. The function isn't suitable as a "real" log parser. I originally proposed something similar to your solution to my client.

The client didn't like that because it wasn't dynamic. Every record you had to run the script..every time you looked at the log.

The client was saving the username, along with what was modified in a field. They had thousands of records containing 0 to 500 revisions.
They just wanted to be able to enter a username and see what they had changed.
However, you point out an important limitation.
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Under construction. Email me your wish list for improvements.