• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Terminal grep from AS
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Terminal grep from AS


  • Subject: Re: Terminal grep from AS
  • From: "Adam K. Wuellner" <email@hidden>
  • Date: Thu, 27 Jan 2005 15:23:04 -0600

On Jan 27, 2005, at 4:10 AM, Goran Ehn wrote:

I'm stuck, could some please show with a sample on how to use 'do shell script' with Grep.
I want to search a string for specific tags or words in order to find the needed insertion points. My case is that I receive a large text string and I want to split this string into chunks after a given pattern and I do not whish to use external tools like BBedit or Satimage to do this.

On Jan 27, 2005, at 1: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>

AFAIK, grep can only return whole lines containing the pattern to be searched for, with or without the filename and line number, OR a count of the number of matches. I do not think it can be made to return the portion of a line that the pattern actually matched.

Here is a solution in pure AS (the file 'test.xml' was populated with the sample XML you provided above):

set to ( "macadam:Users:akw:test.xml

set 's text item delimiters to {""}
set
to of 's text items
repeat with
from to of
set
's text item delimiters to {""}
set
of to of text items of of
repeat with
from to of of
set
's text item delimiters to {""}
set
of of to text item of of of
end repeat
end repeat
--
partial_res: {{"This is ","a part ","of the test text."},{"This is"," another text part."}}
 _______________________________________________
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

  • Follow-Ups:
    • Re: Terminal grep from AS
      • From: Christopher Nebel <email@hidden>
References: 
 >Terminal grep from AS (From: Goran Ehn <email@hidden>)
 >Re: Terminal grep from AS (From: daniel <email@hidden>)
 >Re: Terminal grep from AS (From: Goran Ehn <email@hidden>)

  • Prev by Date: Re: Terminal grep from AS
  • Next by Date: Re: syntax problem for reading an xml file in a bundle
  • Previous by thread: Re: Terminal grep from AS
  • Next by thread: Re: Terminal grep from AS
  • Index(es):
    • Date
    • Thread