Welcome to the Mythicsoft Q&A site for:

- Agent Ransack
- FileLocator Lite
- FileLocator Pro

Please feel free to ask any questions on these products or even answer other community member questions.

Useful Links:

- Contact Us
- Help Manuals
- Mythicsoft Home
0 votes

First of all I am totally newbie with scripting.
My txt file example >>

![alt text] [1]
[1]: http://i.stack.imgur.com/H9Q3l.jpg

I want a script to search for term "Black" which located under "Colour" which located under "Clothes".
so the script should highlight only "Black" in line 7.
I tried Regex but it seems it doesn't fit to do this task

Yes Dave, That is exactly what I want to do. I don't understand what you mean about "source documents", They are just txt files.

by (30 points)

You probably could do something like that but just to make sure I understand... you have a text file with TAB indented levels. You want to be able to search that text file for information at a certain indented level dependent on the parent, correct? Can I ask what the source documents are?

Any answer?

1 Answer

0 votes

Try this:

// Tree search script - Searches for text in a file that is using a tab indented data structure. 
// Copyright (C) Mythicsoft  Ltd 2014

var parentLevels = new Array("", "", "", "", "", "", "", "");
var strSearchFor = SearchParms.ContainingTextCustomParm;
var regexCompare = new RegExp(strSearchFor, "i");

function isValidLine( nLineNum, strText )
    var bIsValid = false;
        // First calculate the tab indentation

        var nTabLevel = 0;
        while ((nTabLevel < strText.length) && (strText.charAt(nTabLevel) == "\t"))

        var strThis = strText.substr(nTabLevel);
        parentLevels[nTabLevel] = strThis;

        // Build up the parent string

        var strParent = "";
        for (var nParent = 0; (nParent <= nTabLevel) && (nParent < parentLevels.length) ; ++nParent)
            if (strParent.length > 0)
                strParent += "->";
            strParent += parentLevels[nParent];
        bIsValid = regexCompare.test(strParent);
    catch( e )	{}
    return bIsValid;

Each line will built to include the parent level data using '->' as a separator, e.g, Clothes->Colour->Black. To search simply put the path your looking for in the Parm field.

Run Script

IMPORTANT: Because lines are only passed to script if they've passed the filter you also need to specify a value in Containing Text on the Main tab. Something like * will do.

All lines

by (75.6k points)

Thank you very much