regexp in the shell

Dpk dpk@egr.msu.edu
Thu, 19 Apr 2001 13:10:34 -0400


On Thu, Apr 19, 2001 at 12:53:50PM -0400, Morris, Alex wrote:

   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?  I was
   looking at grep because it does regexp (which would make this easy)
   but it returns lines that match a pattern, it cannot extract text
   from a line.
   
   Any ideas?

echo $myvariable |awk '{print $3}' |cut -d\! -f1

Dennis