<?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 colums in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-colums/m-p/4665071#M677633</link>
    <description>Hi Tom:&lt;BR /&gt;&lt;BR /&gt;Use 'awk' to match and pluck the last field:&lt;BR /&gt;&lt;BR /&gt;# RETURN=$(ps -ef|awk '/pmon_PO/ {print $NF}')&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;For that matter, since you are matching the basename of a process and just want the pid (if any), do:&lt;BR /&gt;&lt;BR /&gt;# PID=$(UNIX95= ps -C ora_pmon_PO -opid=)&lt;BR /&gt;&lt;BR /&gt;Note the whitespace after the 'UNIX95='.  This arms the XPG4 behavior only for the duration of the command line.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
    <pubDate>Thu, 22 Jul 2010 18:25:55 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2010-07-22T18:25:55Z</dc:date>
    <item>
      <title>grep colums</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-colums/m-p/4665070#M677632</link>
      <description>Hi All,&lt;BR /&gt;&lt;BR /&gt;Please help!&lt;BR /&gt;my grep sometime returned with 8 or 9 columns as below.&lt;BR /&gt;how to change my scripts so the return will be more consistent &lt;BR /&gt;my gold is to get "pmon_PO"&lt;BR /&gt; &lt;BR /&gt;#ps -ef|grep pmon&lt;BR /&gt;oracle 27676  1  0 Jun  3  ?  14:08 ora_pmon_PO&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;RETURN=`ps -ef|grep [p]mon_PO|awk '{print $9}'`&lt;BR /&gt; if [ "ora_pmon_$DB" = "$RETURN" ]&lt;BR /&gt;     then&lt;BR /&gt;          exit 0&lt;BR /&gt; else&lt;BR /&gt;&lt;BR /&gt;Thank for your help.&lt;BR /&gt;Tom,</description>
      <pubDate>Thu, 22 Jul 2010 18:01:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-colums/m-p/4665070#M677632</guid>
      <dc:creator>tom quach_1</dc:creator>
      <dc:date>2010-07-22T18:01:33Z</dc:date>
    </item>
    <item>
      <title>Re: grep colums</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-colums/m-p/4665071#M677633</link>
      <description>Hi Tom:&lt;BR /&gt;&lt;BR /&gt;Use 'awk' to match and pluck the last field:&lt;BR /&gt;&lt;BR /&gt;# RETURN=$(ps -ef|awk '/pmon_PO/ {print $NF}')&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;For that matter, since you are matching the basename of a process and just want the pid (if any), do:&lt;BR /&gt;&lt;BR /&gt;# PID=$(UNIX95= ps -C ora_pmon_PO -opid=)&lt;BR /&gt;&lt;BR /&gt;Note the whitespace after the 'UNIX95='.  This arms the XPG4 behavior only for the duration of the command line.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 22 Jul 2010 18:25:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-colums/m-p/4665071#M677633</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-07-22T18:25:55Z</dc:date>
    </item>
    <item>
      <title>Re: grep colums</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-colums/m-p/4665072#M677634</link>
      <description>Thanks James,&lt;BR /&gt;it works,&lt;BR /&gt;&lt;BR /&gt;#ps  -ef|awk ' /pmon_PO/ {print $NF}'&lt;BR /&gt;ora_pmon_OP&lt;BR /&gt;$NF}&lt;BR /&gt;&lt;BR /&gt;but sometimes it returned with "$NF"&lt;BR /&gt; how can i get rid of it.&lt;BR /&gt;&lt;BR /&gt;Thanks very much,&lt;BR /&gt;Tom&lt;BR /&gt;</description>
      <pubDate>Thu, 22 Jul 2010 20:45:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-colums/m-p/4665072#M677634</guid>
      <dc:creator>tom quach_1</dc:creator>
      <dc:date>2010-07-22T20:45:31Z</dc:date>
    </item>
    <item>
      <title>Re: grep colums</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-colums/m-p/4665073#M677635</link>
      <description>Hi (again) Tom:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; but sometimes it returned with "$NF"&lt;BR /&gt;how can i get rid of it.&lt;BR /&gt;&lt;BR /&gt;Yes, indeed this can happen and I should have accounted for it in my original post.  Mea culpa.&lt;BR /&gt;&lt;BR /&gt;Exercise this several times and occasionally you will see the extra line representing the 'awk' process we launched:&lt;BR /&gt;&lt;BR /&gt;# ps -ef|awk '/cron/ {print $0,$NF}'&lt;BR /&gt;    root  1555     1  0  Mar  3  ?         0:33 /usr/sbin/cron /usr/sbin/cron&lt;BR /&gt;    root 20538 11785  1 18:07:41 pts/0     0:00 awk /cron/ {print $0,$NF} $0,$NF}&lt;BR /&gt;&lt;BR /&gt;We don't want the last field of the second line!&lt;BR /&gt;&lt;BR /&gt;We can do:&lt;BR /&gt;&lt;BR /&gt;# ps -ef|awk '/cron/ &amp;amp;&amp;amp; !/awk/ {print $NF}'&lt;BR /&gt;&lt;BR /&gt;...which is the same rationale you see for command like:&lt;BR /&gt;&lt;BR /&gt;# ps -ef|grep cron|grep -v cron&lt;BR /&gt;&lt;BR /&gt;This all underscores, the value of the 'UNIX95' behavior I suggested where you exactly match a process basename ('-C &lt;NAME&gt;').&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;&lt;/NAME&gt;</description>
      <pubDate>Thu, 22 Jul 2010 21:17:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-colums/m-p/4665073#M677635</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-07-22T21:17:45Z</dc:date>
    </item>
    <item>
      <title>Re: grep colums</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-colums/m-p/4665074#M677636</link>
      <description>Hi James,&lt;BR /&gt;&lt;BR /&gt;thanks for your help,&lt;BR /&gt;i add the "grep at the end and it seems good enough for me.&lt;BR /&gt;Thanks again,&lt;BR /&gt;Tom&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 22 Jul 2010 21:32:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-colums/m-p/4665074#M677636</guid>
      <dc:creator>tom quach_1</dc:creator>
      <dc:date>2010-07-22T21:32:37Z</dc:date>
    </item>
    <item>
      <title>Re: grep colums</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-colums/m-p/4665075#M677637</link>
      <description>Hi (again) tom:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; i add the "grep at the end and it seems good enough for me.&lt;BR /&gt;&lt;BR /&gt;Don't mix 'grep' and 'awk' in a pipelined command.  DOing so adds and extra process that most often can be subjugated into 'awk':&lt;BR /&gt;&lt;BR /&gt;Look again at:&lt;BR /&gt;&lt;BR /&gt;# ps -ef|awk '/cron/ &amp;amp;&amp;amp; !~/awk/ {print $NF}'&lt;BR /&gt;&lt;BR /&gt;This looks for a match to 'cron' only if there isn't the pattern 'awk' in the same line.  Using the original snippet I offered, we amend it to be:&lt;BR /&gt;&lt;BR /&gt;# RETURN=$(ps -ef|awk '/pmon_PO/ &amp;amp;&amp;amp; !~/awk/ {print $NF}')&lt;BR /&gt;&lt;BR /&gt;...no 'grep' needed and a process and some I/O saved.  Thing green :-)&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 22 Jul 2010 21:48:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-colums/m-p/4665075#M677637</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-07-22T21:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: grep colums</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-colums/m-p/4665076#M677638</link>
      <description>&amp;gt; #ps -ef|grep pmon&lt;BR /&gt; &lt;BR /&gt;Very dangerous. Never mix grep and ps! It isn't necessary and when you do, you get nasty results:&lt;BR /&gt; &lt;BR /&gt;ps -ef | grep sh&lt;BR /&gt; &lt;BR /&gt;But I was looking for the sh processes and got bash and ksh and unhashdaemon and even sherri, my receptionist!&lt;BR /&gt; &lt;BR /&gt;Seriously, grep cannot be made to stay inside a field (column is so punch-cardy). While awk can extract the last field, what if the process you want is part of the command line, like grep ora_pmon_PO?&lt;BR /&gt; &lt;BR /&gt;This construct will give you an EXACT match for all processes with the name ora_pmon_PO:&lt;BR /&gt; &lt;BR /&gt;UNIX95=1 ps -f -C ora_pmon_PO&lt;BR /&gt;&lt;BR /&gt;also:&lt;BR /&gt;&lt;BR /&gt;UNIX95=1 ps -f -C sh&lt;BR /&gt; &lt;BR /&gt;Notice: no grep. NOTE: UNIX95=1 is required to enable additional options such as -C, -H and -o. The -o option is really useful to customize your ps command:&lt;BR /&gt; &lt;BR /&gt;UNIX95=1 ps -C ora_pmon_PO -o pid,vsz,args&lt;BR /&gt; &lt;BR /&gt;The man page also tells you that you never grep for pid -- just use the -p option. Check out -H too.&lt;BR /&gt; &lt;BR /&gt;Help stamp out ps|grep in HP-UX...</description>
      <pubDate>Thu, 22 Jul 2010 22:18:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-colums/m-p/4665076#M677638</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2010-07-22T22:18:42Z</dc:date>
    </item>
  </channel>
</rss>

