[regexp in the shell]
Matt Graham
danceswithcrows@usa.net
19 Apr 2001 13:14:22 EDT
"Morris, Alex" <alex.morris@jnli.com> wrote:
> ---------------------------------------------
> Attachment:
> MIME Type: multipart/alternative
...plain text, man, plain text.
> I'm using the ksh shell and have a problem. I have a variable in one of my
> scripts, and I need to extract a few characters from the variable and store
> it in another variable (preferably without using a temp file).
>
> The basic format of the variable is:
>
> IMPLEMNTATION ----------------------- xxxxxxxx!yyyyy 1 record(s) selected.
>
> I'm trying to extract that "xxxxxxxx" part. The number of dashes, "-", is
> not static. The number of "x"'s is not static. And the number of "y"'s is
> not static. I figure that I can search through the variable and pull out
> everything between "----- " and "!", but I don't know how to search through
> the variable...
>
> Any idea how to do this, or what function to investigate?
sed?
echo " BOOGA ------ joebob ! foo records selected" | sed -e 's/\!.*$//'
-e 's/^.*-//'
...returns "joebob" which is what I think you want this thing to do. Just
echo the variable and pipe echo's output through the sed, then use backticks
to assign the result to a new variable? I'm sure there's a more efficient way
to do this. It might involve turning the shell script into a Perl script, but
that would probably be a Good Thing since doing complex stuff in shell is a
PITA. HTH,
--
Matt G / Dances With Crows
There is no Darkness in Eternity
But only Light too dim for us to see
____________________________________________________________________
Get free email and a permanent address at http://www.netaddress.com/?N=1