Re: Terminal grep from AS
Re: Terminal grep from AS
- Subject: Re: Terminal grep from AS
- From: "Steven D.Majewski" <email@hidden>
- Date: Fri, 28 Jan 2005 13:48:00 -0500
On Jan 27, 2005, at 2:55 PM, Goran Ehn wrote:
Sorry if I was a bit unclear before, here is a short sample. I just
want to replace the Satimage grep and use the terminal grep instead,
that is to strip the code off and get the text into lists one block at
the time. --> {"This is ","a part ","of the test text."} -->{"This
is","another text part."}
I'm somewhat unfamiliar with the possibilities when using 'do shell
script', and I just want a sample of how I can pass the grep command +
string and retrieve the result.
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<root>
<block id="1">
<text>This is </text><text>a part </text><text>of the test
text.</text>
</block>
<block id="2">
<text>This is</text><text> another text part.</text>
</block>
</root>
Regards
/goran
As other have noted, 'grep' won't do what you want.
If what you want is to merely strip out the tags and pass on the text
content,
then:
sed -e 's/<[^>]*>//g'
(called via 'do shell script' ) will get you:
This is a part of the test text.
This is another text part.
But if you're interested in the structure ( and asking for the results
as a list seems to imply that's what you want ) then you may be better
of using an XML parser.
For example, you can use python's re.split ( or the Perl or Ruby
equivalent )
to tokenize the text into a list of tags & content, but then to get the
structure and containment, you still have to walk the list and match up
the start and end tags.
You can, as Chris Nebel suggested, use an XML parser OSAX from
Applescript,
or you can write Python/Perl/Ruby code and call it from 'do shell
script'
( But that is more than a couple of lines of python, and requires
explaining
SAX if you're not familiar with it, so I'm not going to try to
provide an example unless you can be more explicit about what you
need. )
( I would THINK this would be quite simple to do in XSLT, but that's
something
I'm just starting to try to learn. )
-- Steve Majewski - University of Virginia Alderman Library
_______________________________________________
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