Re: Finding lines containing foo in a file
Re: Finding lines containing foo in a file
- Subject: Re: Finding lines containing foo in a file
- From: "Nigel Garvey" <email@hidden>
- Date: Thu, 22 Dec 2005 22:42:20 +0000
John Hawkinson wrote on Thu, 22 Dec 2005 11:44:12 -0500:
>Nigel Garvey <email@hidden> wrote on Thu, 22 Dec 2005
>at 16:32:57 +0000 in <email@hidden>:
>
>> However, if any of the UNIX fans here know how to coax one 'grep' call
>> into accepting several search strings at once, without erroring on any
>> not found, it might still be in with a chance.
>
>You must use egrep (Extended/expression grep, depending on who you ask),
>and separate regular expressions with |'s (which you must quote from the
>shell). E.g.:
>
> egrep 'foo|bar|baz' myfile
Ah. Very nice. Thanks, John. Very nearly the same speed (with only six
input strings) as my vanilla loop. Probably faster with more. Strings not
found are simply ignored. Output is Unicode text regardless of the original.
on GetLinesFromFile(searchList, filePath)
set filePath to quoted form of POSIX path of filePath
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "|"
set shellScript to "egrep '" & searchList & "' " & filePath
set AppleScript's text item delimiters to astid
return paragraphs of (do shell script shellScript)
end GetLinesFromFile2
set searchList to {"32327", "25397", "29372", "30087", "31316", "32151"}
set filePath to (path to desktop as Unicode text) & "A text file.txt"
GetLinesFromFile(searchList, filePath)
NG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden