MACSCRPT Archives

November 2006

MACSCRPT@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Peter Boardman <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Mon, 20 Nov 2006 10:29:22 +0000
Content-Type:
text/plain
Parts/Attachments:
text/plain (42 lines)
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.

ATOM RSS1 RSS2