On Wed, Sep 9, 2009 at 12:46 PM, Stockly, Ed<[log in to unmask]> wrote:
> Do shell script "grep ^" & foo & "\|" & myFile

Hm. That doesn't compile for me.  You need to double the backslash.

Or lose it entirely.  Are you trying to match a literal pipe character
in the string?  If so, you want it without the backslash for grep(1).
With the backslash it means "or" and you're matching any line that
contains the empty string, which is all of them.

You can use that feature to your advantage to solve your problem, however:

grep '^\(foo\|bar\|zoo\)|'  will match lines starting with 'foo|',
'bar|', or 'zoo|'.


Something like this from AS:

set lookForThese to { "foo", "bar", "zoo" }
set text item delimiters to "\\|"
set thePattern to "^\\(" & (lookForThese as text) & "\\)|"
do shell script "grep " & quoted form of thePattern & " myFile"

> Takes a while, but it works.

If grep is slow, egrep might be faster.  You have to swap the
backslashes, though:
grep '^\(foo\|bar\|zoo\)|' becomes egrep '^(foo|bar|zoo)\|'


-- 
Mark J. Reed <[log in to unmask]>