Subject: | |
From: | |
Reply To: | |
Date: | Tue, 15 Apr 2008 13:23:00 -0400 |
Content-Type: | text/plain |
Parts/Attachments: |
|
|
On Tue, Apr 15, 2008 at 1:09 PM, Mark J. Reed <[log in to unmask]> wrote:
> If I was right about the goal, here's one way to do it from the command line:
>
> $ cat /file/with/just/numbers /file/with/pairs | awk '(NF==1)
> {seen[$1]=1} (NF==2 && seen[$1]) {print}'
or just
awk '(NF==1){seen[$1]=1}(NF==2 && seen[$1]){print}' /file/with/numbers
/file/with/pairs >/output/file
which saves a pointless cat process. That puts the result in
/output/file; change as desired, or lop off entirely to just spit out
the matching lines. Here's a snippet of (untested) AppleScript that
should yield an array of records containing 'number' and 'letters'
fields:
set matchingLines to paragraphs of do shell script "awk
'(NF==1){seen[$1]=1}(NF==2 && seen[$1]){print}' " & quoted form of
POSIX path of fileWithNumbers & " " & quoted form of POSIX path of
fileWithPairs
set matchingPairs to {}
set oldTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to space
repeat with aLine in matchingLines
set end of matchingPairs to {number: text item 1 of aLine,
letters: text item 2 of aLine}
end repeat
set AppleScript's text item delimiters to oldTID
--
Mark J. Reed <[log in to unmask]>
|
|
|