regexp in the shell

Morris, Alex alex.morris@jnli.com
Thu, 19 Apr 2001 13:21:48 -0400


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C0C8F5.336C2BE6
Content-Type: text/plain;
	charset="iso-8859-1"

Thank you!

That worked like a charm, I really appreciate it :)

- Alex Morris

-----Original Message-----
From: Dpk [mailto:dpk@egr.msu.edu]
Sent: Thursday, April 19, 2001 1:11 PM
To: Morris, Alex
Cc: 'linux-user@egr.msu.edu'
Subject: Re: regexp in the shell


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

------_=_NextPart_001_01C0C8F5.336C2BE6
Content-Type: text/html;
	charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2650.12">
<TITLE>RE: regexp in the shell</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=2>Thank you!</FONT>
</P>

<P><FONT SIZE=2>That worked like a charm, I really appreciate it :)</FONT>
</P>

<P><FONT SIZE=2>- Alex Morris</FONT>
</P>

<P><FONT SIZE=2>-----Original Message-----</FONT>
<BR><FONT SIZE=2>From: Dpk [<A HREF="mailto:dpk@egr.msu.edu">mailto:dpk@egr.msu.edu</A>]</FONT>
<BR><FONT SIZE=2>Sent: Thursday, April 19, 2001 1:11 PM</FONT>
<BR><FONT SIZE=2>To: Morris, Alex</FONT>
<BR><FONT SIZE=2>Cc: 'linux-user@egr.msu.edu'</FONT>
<BR><FONT SIZE=2>Subject: Re: regexp in the shell</FONT>
</P>
<BR>

<P><FONT SIZE=2>On Thu, Apr 19, 2001 at 12:53:50PM -0400, Morris, Alex wrote:</FONT>
</P>

<P><FONT SIZE=2>&nbsp;&nbsp; I'm using the ksh shell and have a problem.&nbsp; I have a variable in one of my</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp; scripts, and I need to extract a few characters from the variable and store</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp; it in another variable (preferably without using a temp file).</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp; </FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp; The basic format of the variable is:</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp; </FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp; IMPLEMNTATION&nbsp; ----------------------- xxxxxxxx!yyyyy 1 record(s) selected.</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp; </FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp; I'm trying to extract that &quot;xxxxxxxx&quot; part.&nbsp; The number of dashes,</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp; &quot;-&quot;, is not static.&nbsp; The number of &quot;x&quot;'s is not static.&nbsp; And the</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp; number of &quot;y&quot;'s is not static.&nbsp; I figure that I can search through</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp; the variable and pull out everything between &quot;----- &quot; and &quot;!&quot;, but</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp; I don't know how to search through the variable...</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp; </FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp; Any idea how to do this, or what function to investigate?&nbsp; I was</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp; looking at grep because it does regexp (which would make this easy)</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp; but it returns lines that match a pattern, it cannot extract text</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp; from a line.</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp; </FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp; Any ideas?</FONT>
</P>

<P><FONT SIZE=2>echo $myvariable |awk '{print $3}' |cut -d\! -f1</FONT>
</P>

<P><FONT SIZE=2>Dennis</FONT>
</P>

</BODY>
</HTML>
------_=_NextPart_001_01C0C8F5.336C2BE6--