On 2006-11-18, at 17:29.0, Paul Berkowitz wrote:
> What I was asking was if someone who knows shell script and other
> Unix languages like Perl, Python etc. could supply me with such a
> method for getting the line numbers of found text.
Here's an 'etc' solution...;) I like and will keep your 'do shell
script' handler in case I ever need it, although it's a pity one has
to do all this quoting, CRuLFing, and backslashing to glue the
languages together. Unavoidable, I expect.
This script line finds items that are in list1 but not in list2, and
returns any duplicates in the list (that's what the 'true' flag is
doing):
set scpt to {"newlisp -e '(silent (map println (difference (parse
\"" & list1 & "\" \"\\n\") (parse \"" & list2 & "\" \"\\n\")
true ) ) )'"}
Example:
set list1 to {"paul", 2, 4, "this is a test", "another test", "test
test test", "this", 1, 2, 4}
set list2 to {"this", "this is a test", 2, "this is not a test", 3,
"paul"}
--> {"4", "another test", "test test test", "1", "4"}
and finding indices is easy too - these are 0-based, and refer to the
first occurrence of each item of list1 in list2:
set scpt to {"newlisp -e '(silent (map (fn (i) (println (first (ref
i (parse \"" & list2 & "\" \"\\n\"))))) (parse \"" & list1 & "\" \"\\n
\"))) '"}
--> {"5", "2", "nil", "1", "nil", "nil", "0", "nil", "2", "nil"}
"nil" seems a suitable value to return for no match...
Similar 'map' solutions are available in other languages too, I think.
|