<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: grep question in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567797#M227664</link>
    <description>Sorry to put a damper on Mel's solution (grep -v [0-9]), but isn't the output of ps -ef always going to contain a number in in the PID?&lt;BR /&gt;&lt;BR /&gt;Mark Syder (like the drink but spelt different)</description>
    <pubDate>Tue, 21 Jun 2005 09:57:06 GMT</pubDate>
    <dc:creator>MarkSyder</dc:creator>
    <dc:date>2005-06-21T09:57:06Z</dc:date>
    <item>
      <title>grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567788#M227655</link>
      <description>ps -ef | grep -v grep | grep "SVR"&lt;BR /&gt;&lt;BR /&gt;SVR&lt;BR /&gt;SVR1&lt;BR /&gt;SVR2&lt;BR /&gt;SVR4&lt;BR /&gt;SVR5&lt;BR /&gt;&lt;BR /&gt;How to grep "SVR" so that it returns only&lt;BR /&gt;SVR ? Thank you.&lt;BR /&gt;</description>
      <pubDate>Tue, 21 Jun 2005 09:41:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567788#M227655</guid>
      <dc:creator>Mike_Ca Li</dc:creator>
      <dc:date>2005-06-21T09:41:35Z</dc:date>
    </item>
    <item>
      <title>Re: grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567789#M227656</link>
      <description>ps -ef | grep -i grep | grep "SVR "</description>
      <pubDate>Tue, 21 Jun 2005 09:44:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567789#M227656</guid>
      <dc:creator>Steven E. Protter</dc:creator>
      <dc:date>2005-06-21T09:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567790#M227657</link>
      <description>If you were reading from a file, you would anchor the regular expression&lt;BR /&gt;grep -E -e '^SVR$' but since you are grepping the output of ps I would look for ' SVR ' (spaces surrounding the pattern).&lt;BR /&gt;&lt;BR /&gt;ps -ef | grep -v grep | grep -E -e ' SVR '</description>
      <pubDate>Tue, 21 Jun 2005 09:48:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567790#M227657</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2005-06-21T09:48:31Z</dc:date>
    </item>
    <item>
      <title>Re: grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567791#M227658</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I'm not sure that you can do this with grep.&lt;BR /&gt;If you are sure that the pattern there is on the end of string, you can use SVR$, or, if you are sure that after the pattern there is a space, use "SVR ".&lt;BR /&gt;IMHO, the best way is &lt;BR /&gt;ps -ef |awk '$8=="SVR" {print}'&lt;BR /&gt;&lt;BR /&gt;HTH</description>
      <pubDate>Tue, 21 Jun 2005 09:49:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567791#M227658</guid>
      <dc:creator>Victor Fridyev</dc:creator>
      <dc:date>2005-06-21T09:49:57Z</dc:date>
    </item>
    <item>
      <title>Re: grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567792#M227659</link>
      <description>ps -ef | grep -v grep | grep "SVR" | grep -v [0-9]&lt;BR /&gt;&lt;BR /&gt;if the suffix is always going to benumerals, this should do the trick.</description>
      <pubDate>Tue, 21 Jun 2005 09:51:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567792#M227659</guid>
      <dc:creator>Mel Burslan</dc:creator>
      <dc:date>2005-06-21T09:51:06Z</dc:date>
    </item>
    <item>
      <title>Re: grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567793#M227660</link>
      <description>The -x switch to grep will return exactly.&lt;BR /&gt;&lt;BR /&gt;ps -ef | grep -x SVR</description>
      <pubDate>Tue, 21 Jun 2005 09:52:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567793#M227660</guid>
      <dc:creator>Rick Garland</dc:creator>
      <dc:date>2005-06-21T09:52:15Z</dc:date>
    </item>
    <item>
      <title>Re: grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567794#M227661</link>
      <description>the output you list can't be the output of the command you list, since "ps -ef" generates several columns of output.&lt;BR /&gt;&lt;BR /&gt;in any case, I think you want something like:&lt;BR /&gt;&lt;BR /&gt; grep -e "SVR[[:space:]]" -e "SVR$"&lt;BR /&gt;&lt;BR /&gt;at the end of your command - this will prevent SVR1, SVR2, etc., from being displayed.  this searches for SVR followed by either whitespace or end-of-line, which should get you what you want.  it won't prevent something like ASVR or BSVR, however, but I'm guessing that won't be an issue in your case.&lt;BR /&gt;&lt;BR /&gt;--Greg</description>
      <pubDate>Tue, 21 Jun 2005 09:54:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567794#M227661</guid>
      <dc:creator>Greg Vaidman</dc:creator>
      <dc:date>2005-06-21T09:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567795#M227662</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;The switch -x works for exact string, i.e if you have only SVR in the string. For a string, which contain SVR as a word -x does not work. 8((((</description>
      <pubDate>Tue, 21 Jun 2005 09:54:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567795#M227662</guid>
      <dc:creator>Victor Fridyev</dc:creator>
      <dc:date>2005-06-21T09:54:44Z</dc:date>
    </item>
    <item>
      <title>Re: grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567796#M227663</link>
      <description>Whoops, take that back, no -x switch&lt;BR /&gt;</description>
      <pubDate>Tue, 21 Jun 2005 09:57:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567796#M227663</guid>
      <dc:creator>Rick Garland</dc:creator>
      <dc:date>2005-06-21T09:57:04Z</dc:date>
    </item>
    <item>
      <title>Re: grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567797#M227664</link>
      <description>Sorry to put a damper on Mel's solution (grep -v [0-9]), but isn't the output of ps -ef always going to contain a number in in the PID?&lt;BR /&gt;&lt;BR /&gt;Mark Syder (like the drink but spelt different)</description>
      <pubDate>Tue, 21 Jun 2005 09:57:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567797#M227664</guid>
      <dc:creator>MarkSyder</dc:creator>
      <dc:date>2005-06-21T09:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567798#M227665</link>
      <description>oops.. my bad&lt;BR /&gt;ps -ef | grep -v grep | grep "SVR" | grep -v SVR[0-9]&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 21 Jun 2005 10:34:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567798#M227665</guid>
      <dc:creator>Mel Burslan</dc:creator>
      <dc:date>2005-06-21T10:34:28Z</dc:date>
    </item>
    <item>
      <title>Re: grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567799#M227666</link>
      <description>does it always show up first in the list?&lt;BR /&gt;&lt;BR /&gt;ps -ef |grep SVR |head -1&lt;BR /&gt;&lt;BR /&gt;Rgds...Geoff</description>
      <pubDate>Tue, 21 Jun 2005 11:11:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567799#M227666</guid>
      <dc:creator>Geoff Wild</dc:creator>
      <dc:date>2005-06-21T11:11:01Z</dc:date>
    </item>
    <item>
      <title>Re: grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567800#M227667</link>
      <description>Get GNU grep if you don't have it yet!&lt;BR /&gt;&lt;BR /&gt;# grep -w SVR&lt;BR /&gt;&lt;BR /&gt;  -w, --word-regexp         force PATTERN to match only whole words&lt;BR /&gt;&lt;BR /&gt;Get GNU grep if you don't have it yet!&lt;BR /&gt;Get GNU grep if you don't have it yet!&lt;BR /&gt;Get GNU grep if you don't have it yet!&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn&lt;BR /&gt;&lt;BR /&gt;PS. If you build it yourself from scratch, install pcre first, and you get a grep that optionally supports Perl Compatible Regular Expressions!&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have More FUN! (TM) H.Merijn</description>
      <pubDate>Tue, 21 Jun 2005 12:23:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567800#M227667</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2005-06-21T12:23:28Z</dc:date>
    </item>
    <item>
      <title>Re: grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567801#M227668</link>
      <description>Using grep and ps together is a very unstable combination. grep does not care at all about what matches on the line. It could a user name, a process name or it might be part of the command line argument list. If you are looking for a specific process named SVR, then the solution is trivial (no grep at all):&lt;BR /&gt; &lt;BR /&gt;UNIX95= ps -fC SVR&lt;BR /&gt; &lt;BR /&gt;Type the command as shown. The UNIX95= is a one line method to set a variable temporarily. In the man page for ps, you'll see a number of options (-C -H -o) that are "XPG4" options. But they are disabled when UNIX95 does not exist. You don't want to set UNIX95 on a separate line as it affects other commands and libraries. So use the above example to find just SVR (or just SVR1, etc). The -C is an exact process name match built into ps.&lt;BR /&gt; &lt;BR /&gt;A good rule of thumb is to always avoid using grep and ps together. If you need to find a list of processes by PID, use the -p option. Processes by owner: -u option. Create a customized output from ps: use -o&lt;BR /&gt; &lt;BR /&gt;Here's a command line that shows only processes named sh (not ksh, not csh, not hasdaemon, not username trish, etc) and shows just user, PID and PPID, process size in Kbytes, and the command line for each process:&lt;BR /&gt; &lt;BR /&gt;UNIX95= ps -C sh &lt;BR /&gt; &lt;BR /&gt;UNIX95=&lt;BR /&gt;</description>
      <pubDate>Tue, 21 Jun 2005 13:12:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567801#M227668</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2005-06-21T13:12:54Z</dc:date>
    </item>
    <item>
      <title>Re: grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567802#M227669</link>
      <description>Oops, the last line should read:&lt;BR /&gt; &lt;BR /&gt;UNIX95= ps -C sh -o user,pid,ppid,vsz,args&lt;BR /&gt; &lt;BR /&gt;The reason that grep fails is that it has no concept of field matching...it's just a left to right comparison on each line.</description>
      <pubDate>Tue, 21 Jun 2005 13:17:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567802#M227669</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2005-06-21T13:17:10Z</dc:date>
    </item>
    <item>
      <title>Re: grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567803#M227670</link>
      <description>what about perl.... it has one of the best regular expression engines available PLUS boolean logic ... etc ..  To demonstaate here is what I'd do to print out the line AND the headder whilst removing the perl command itself...&lt;BR /&gt;&lt;BR /&gt;ps -fe | perl -ane 'print if ( ! m/perl.*SVR[0-9]*/ &amp;amp;&amp;amp; (m/SVR[0-9]*/ || m/PID/ ))'&lt;BR /&gt;&lt;BR /&gt;     UID   PID  PPID  C    STIME TTY       TIME COMMAND&lt;BR /&gt;kilbours 25025     1  0  May  5  ?         0:00 SVR&lt;BR /&gt;kilbours 10393     1  0  Mar  1  ?         0:00 SVR1&lt;BR /&gt;kilbours 10393     1  0  Mar  1  ?         0:00 SVR199&lt;BR /&gt;kilbours 10393     1  0  Mar  1  ?         0:00 SVR0&lt;BR /&gt;&lt;BR /&gt;A few pointers about how flexible perl is  ".*" mean match anything 0 or more times "[0-9]*" means match any number 0 or more times.  So the above says&lt;BR /&gt;&lt;BR /&gt;o ! m/perl.*SVR[0-9]* DONT print if there is a line that starts perl and has SVR after it so ???perlSVR??? would do, and so would perl xxxxxxxxx 1234 SVR yyyy etc.&lt;BR /&gt;o m/SVR[0-9]*/ DO print if you see a line with SVR ending with any number of numerals e.g ???SVR??? or ????SVR0???? or ???SVR1???&lt;BR /&gt;o m/PID/ Do print if you see a line with PID in it (the headder for example)&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;&lt;BR /&gt;Tim&lt;BR /&gt;</description>
      <pubDate>Tue, 21 Jun 2005 16:10:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567803#M227670</guid>
      <dc:creator>Tim D Fulford</dc:creator>
      <dc:date>2005-06-21T16:10:49Z</dc:date>
    </item>
    <item>
      <title>Re: grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567804#M227671</link>
      <description>oops .. I'm going way off at a tangent trying to show how flexible perl is and not answering your specific question here..&lt;BR /&gt;&lt;BR /&gt;# ps -fe | perl -ane 'print if ( ! m/perl.*SVR// &amp;amp;&amp;amp; m/\bSVR\b/)'&lt;BR /&gt;&lt;BR /&gt;kilbours 25025     1  0  May  5  ?         0:00 SVR&lt;BR /&gt;&lt;BR /&gt;This will work, but it will also match "SVR -o multithread", but NOT "SVR1 -o multithread" If you also want to get rid of the "-o multithread" bit then&lt;BR /&gt;&lt;BR /&gt;# ps -fe | perl -ane 'print if ( ! m/perl.*SVR/ &amp;amp;&amp;amp; m/\bSVR$/)'&lt;BR /&gt;&lt;BR /&gt;It is also usual to only want, say the PID &amp;amp; cmd for this you can use&lt;BR /&gt;&lt;BR /&gt;ps -fe | perl -ane 'print "$F[1] $F[-1]\n " if ( ! m/perl.*SVR/ &amp;amp;&amp;amp; m/\bSVR$/ )'&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;&lt;BR /&gt;Tim</description>
      <pubDate>Tue, 21 Jun 2005 16:23:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/3567804#M227671</guid>
      <dc:creator>Tim D Fulford</dc:creator>
      <dc:date>2005-06-21T16:23:54Z</dc:date>
    </item>
  </channel>
</rss>

