Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!rpi!brutus.cs.uiuc.edu!wuarchive!decwrl!shelby!agate!saturn!ssyx.ucsc.edu!sirkm From: sirkm@ssyx.ucsc.edu (Greg Anderson) Newsgroups: comp.sys.mac.hypercard Subject: Re: Need Help with Text File Searching Keywords: grep Message-ID: <10707@saturn.ucsc.edu> Date: 9 Feb 90 20:49:53 GMT References: <2935@bingvaxu.cc.binghamton.edu> Sender: usenet@saturn.ucsc.edu Reply-To: sirkm@ssyx.ucsc.edu (Greg Anderson) Organization: UC Santa Cruz; Division of Social Sciences Lines: 65 I tried to send this via mail, but it bounced. The following describes a "grep" XFCN I wrote & its pertinence to searching for definitions in a file. ----------------- I have an XFCN that _might_ help you. Your file format currently is: Word Definition Definition Definition If you could change this to: Word Definition Definition Definition Or: Word\ Definition\ Definition\ Definition Or perhaps even: Word*Definition*Definition*Definition Then you could use my XFCN. If changing your data format is inconvenient, then perhaps you could modify my source code so that it searches four-line blocks instead of single-line blocks. It has modes that allows it to consider multiple lines as one single line if subsequent lines are indented (as in the first example) or if the end of continued lines have trailing backslashes (second example). My XFCN is called "grep", as it works like the unix grep command. You would do the following: put readfile(thefilename) into tmpvar put grep("-im","^Word",tmpvar) into tmpresult if tmpresult is not empty then put line 1 of tmpresult delete line 1 of tmpresult -- delete 'Word' put tmpresult end if In the "grep" line, the "-im" selects the flags 'i' (case insensitive search) and 'm' (multi-line search, as in the first example). The "^" before "Word" indicates that grep should only look for lines that BEGIN with "word" as opposed to all lines that contain "word". Grep will return all lines that contain a match. If your definition lines are all indented, they will be considered to be part of the same line as 'word', and will therefore be returned. The advantage of this approach is that your definitions are no longer constrained to three lines. ___\ /___ Greg Anderson ___\ /___ \ \ / / Social Sciences Computing \ \ / / \ /\/\ / University of California, Santa Cruz \ /\/\ / \/ \/ sirkm@ssyx.ucsc.edu \/ \/