Re: Shell script timing, regex
Re: Shell script timing, regex
- Subject: Re: Shell script timing, regex
- From: "Mark J. Reed" <email@hidden>
- Date: Thu, 1 Dec 2005 18:14:25 -0500
On 12/1/05, Andrew Sasaki <email@hidden> wrote:
> > Hi all,
> >
> > I've got a pair o' questions regarding an AppleScript I've got that grabs some files from an ftp site, downloads them and unzips them.
> >
> > First, I'm grapping the filepaths using 'curl' and parsing the names via AS. I'd like to be able to throw some mighty regex-fu at them -- and years of BBEdit use have made me comfortable doing so -- but I can't seem to find the right command/syntax combo to make it happen. Sed? Awk? Grep? I'm not sure which to use, and I can't seem to use regex in a shell script against an AS variable and get the processed result back. Man pages have been less than helpful in this regard.
> >
>
There are osaxen that provide regular expression support within
AppleScript, which I'm sure someone will point to. For chosing a
command to use within do shell script, it depends what you want to do.
It's not entirely clear from your message what you're doing.
Assuming you're doing something like "curl -l
ftp://ftp.somewhere.com/some/directory/", the output is one filename
per line; you can easily restrict it to just the files you care about
by piping it through grep: "curl -s -l
ftp://ftp.somewhere.com/some/directory/ | grep '^d\?e'" will list
files which start with "e" or "de".
If you want to get the additional information about each file that
comes courtesy of curl when called without the -l option, then awk may
be your best bet, since you want to compare your regex against just
the filename and not the rest of the information on the line. The
filename always starts in the 9th field, although it may continue into
more fields if it contains spaces; this little bit of awk gives the
basic idea:
"curl -s ftp://ftp.somewhere.com/some/directory/ | awk '{fn=""; for
(i=9; i<=NF; ++i) { fn = fn$i; } if (fn ~ /^d?e/) { print $0 }}' "
On the other hand, Perl lets you be a little more concise, if a little
less obvious:
curl -s ftp://ftp.somewhere.com/some/directory/ | perl -ane 'print if
join("",@F[8...$#F]) =~ /^d?e/'
> The second issue is that I want to run a second shell script against the downloaded files, and it opens in a new terminal window and starts running before the first shell script is done. Is this as simple as putting the second script in a tell block directed at the first terminal window, or is there A Better Way?
Sorry, I'm confused again. Do you *want* it to start before the first
one finishes? Why does it need a Terminal window?
--
Mark J. Reed <email@hidden>
_______________________________________________
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