<?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/2566786#M30055</link>
    <description>Hi Richard:&lt;BR /&gt;&lt;BR /&gt;You are confused about the way grep works. You don't need the '*' at all.&lt;BR /&gt;&lt;BR /&gt;In example 1)&lt;BR /&gt;The tgu* was expanded by the shell to look for all files beginning with tgu so that your actual grep command was grep tgu_stats.log&lt;BR /&gt;and the only process it found was you grep &lt;BR /&gt;command itself. &lt;BR /&gt;In example 2) tgu_stats.log is a FILE not a PROCESS sops would not find it.&lt;BR /&gt;&lt;BR /&gt;To do this correctly:&lt;BR /&gt;ps -ef | grep "tgu" | grep -v "grep"&lt;BR /&gt;&lt;BR /&gt;The last grep gets rid of the grep process itself.&lt;BR /&gt;&lt;BR /&gt;I hope that clears it up, Clay &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#ps -ef|grep tgu*&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;root 1884 29789 0 15:52:42 pts/td 0:00 grep tgu_stats.log &lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Sat, 18 Aug 2001 20:13:49 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2001-08-18T20:13:49Z</dc:date>
    <item>
      <title>grep question ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/2566785#M30054</link>
      <description>I have what is probably a simple grep question:&lt;BR /&gt;we have a process call tgu_stats&lt;BR /&gt;Example 1. Command and output&lt;BR /&gt;#ps -ef|grep tgu*&lt;BR /&gt;    root  1884 29789  0 15:52:42 pts/td    0:00 grep tgu_stats.log&lt;BR /&gt;&lt;BR /&gt;Example 2. Command and output.&lt;BR /&gt;#ps -ef|grep tgu&lt;BR /&gt;    root  1709 29789  1 15:51:48 pts/td    0:00 grep tgu&lt;BR /&gt;    root   680     1 23 15:46:04 pts/td    0:04 tgu_stats&lt;BR /&gt;&lt;BR /&gt;Why when I grep for tgu* I dont get back the tgu_stats proces? And when I grep for tgu I dont get back tgu_stats.log?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Richard&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 18 Aug 2001 19:55:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/2566785#M30054</guid>
      <dc:creator>someone_4</dc:creator>
      <dc:date>2001-08-18T19:55:23Z</dc:date>
    </item>
    <item>
      <title>Re: grep question ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/2566786#M30055</link>
      <description>Hi Richard:&lt;BR /&gt;&lt;BR /&gt;You are confused about the way grep works. You don't need the '*' at all.&lt;BR /&gt;&lt;BR /&gt;In example 1)&lt;BR /&gt;The tgu* was expanded by the shell to look for all files beginning with tgu so that your actual grep command was grep tgu_stats.log&lt;BR /&gt;and the only process it found was you grep &lt;BR /&gt;command itself. &lt;BR /&gt;In example 2) tgu_stats.log is a FILE not a PROCESS sops would not find it.&lt;BR /&gt;&lt;BR /&gt;To do this correctly:&lt;BR /&gt;ps -ef | grep "tgu" | grep -v "grep"&lt;BR /&gt;&lt;BR /&gt;The last grep gets rid of the grep process itself.&lt;BR /&gt;&lt;BR /&gt;I hope that clears it up, Clay &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#ps -ef|grep tgu*&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;root 1884 29789 0 15:52:42 pts/td 0:00 grep tgu_stats.log &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 18 Aug 2001 20:13:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/2566786#M30055</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2001-08-18T20:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: grep question ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/2566787#M30056</link>
      <description>Richard,&lt;BR /&gt;&lt;BR /&gt;Try with ps -ef|grep 'tgu*' &lt;BR /&gt;&lt;BR /&gt;and see if you get any difference.&lt;BR /&gt;&lt;BR /&gt;-Sri</description>
      <pubDate>Sat, 18 Aug 2001 20:22:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/2566787#M30056</guid>
      <dc:creator>Sridhar Bhaskarla</dc:creator>
      <dc:date>2001-08-18T20:22:31Z</dc:date>
    </item>
    <item>
      <title>Re: grep question ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/2566788#M30057</link>
      <description>And when you do a ps -ef|grep tgu*,&lt;BR /&gt;the shell tries to spawn tgu*. If your current directory has tgu_stats.log, then you won't get the correct output.&lt;BR /&gt;&lt;BR /&gt;So, go to another directory where you don't have anyfile starting with tgu and run this command, you will get the correct output like what you get with ps -ef|grep 'tgu*'&lt;BR /&gt;&lt;BR /&gt;-Sri</description>
      <pubDate>Sat, 18 Aug 2001 20:31:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/2566788#M30057</guid>
      <dc:creator>Sridhar Bhaskarla</dc:creator>
      <dc:date>2001-08-18T20:31:53Z</dc:date>
    </item>
    <item>
      <title>Re: grep question ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/2566789#M30058</link>
      <description>Hi Richard,&lt;BR /&gt;&lt;BR /&gt;Another way to just grep your process is&lt;BR /&gt;ps -ef |grep [t]gu&lt;BR /&gt;This greps for any process starting with t followed by gu and thereby avoids using another grep (for grep -v) but then its a preference issue. &lt;BR /&gt;&lt;BR /&gt;Ofcourse as far as your question is concerned about not getting the expected output when you use tgu*, that is because of the shell expansion.&lt;BR /&gt;&lt;BR /&gt;-HTH&lt;BR /&gt;I am RU</description>
      <pubDate>Sat, 18 Aug 2001 22:00:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/2566789#M30058</guid>
      <dc:creator>linuxfan</dc:creator>
      <dc:date>2001-08-18T22:00:46Z</dc:date>
    </item>
    <item>
      <title>Re: grep question ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/2566790#M30059</link>
      <description>Although every basic sysadmin class teaches the ps piped to grep method, it is very unreliable, especially for scripting. grep is a simple string match so grep tgu matches every line with tgu anything. That means user logins, other programs and arguments on the command line.  That's why you see the 'enhanced' version:&lt;BR /&gt;&lt;BR /&gt;ps -ef | grep -v grep | grep -i &lt;SOMETHING&gt;&lt;BR /&gt;&lt;BR /&gt;where something is what you are looking for.  grep -v grep removes the grep process for tgu, but it also removes a process called grepping and a user name grepguru, which may not be desired.&lt;BR /&gt;&lt;BR /&gt;So to find all processes that have a specific basename (the process name without any leading directories such as /usr/contrib/bin/tgu), use the PowerPill for ps called UNIX95:&lt;BR /&gt;&lt;BR /&gt;UNIX95= ps -fC tgu_stats&lt;BR /&gt;&lt;BR /&gt;No grep needed, and most important, it returns ONLY tgu_stats and not tgu_stats1, etc. Check out the difference between:&lt;BR /&gt;&lt;BR /&gt;ps -ef | grep sh&lt;BR /&gt;UNIX95= ps -fC sh&lt;BR /&gt;&lt;BR /&gt;Wow, what a difference.  The second form (which activates the -C option in XPG4 mode) is really what we want.&lt;BR /&gt;&lt;BR /&gt;Another feature of the PowerPill option is the ability to create a customized output format. SO if you don't need start-time (which varies in format), you can eliminate it.  Consider this form:&lt;BR /&gt;&lt;BR /&gt;UNIX95= ps -C sh -o ruser,pid,args&lt;BR /&gt;&lt;BR /&gt;Now, very simple parsing can be done for the desired information.  See man ps&lt;/SOMETHING&gt;</description>
      <pubDate>Sat, 18 Aug 2001 23:45:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/2566790#M30059</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2001-08-18T23:45:41Z</dc:date>
    </item>
    <item>
      <title>Re: grep question ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/2566791#M30060</link>
      <description>Hi,&lt;BR /&gt;I also prefer "ps -ef | grep [w]hatever" above "ps -ef | grep -v grep | grep whatever".&lt;BR /&gt;&lt;BR /&gt;good one Ramesh!, sorry Bill ;)&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;Thierry.</description>
      <pubDate>Sun, 19 Aug 2001 05:28:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/2566791#M30060</guid>
      <dc:creator>Thierry Poels_1</dc:creator>
      <dc:date>2001-08-19T05:28:33Z</dc:date>
    </item>
    <item>
      <title>Re: grep question ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/2566792#M30061</link>
      <description>I completely agree with Bill. grep -v grep is a very fundamental way of doing things. For ex., I will run into problems if my process name is check_grep_oracle or my user id is grepmaster something like that where grep is an embedded string.&lt;BR /&gt;&lt;BR /&gt;Also, Richard's problem will still exist if we use grep -v grep option. As long as he has tgu_stats.log or anything that starts with tgu in his current directory, he is never going to get tgu_stats in his grep tgu* command.&lt;BR /&gt;&lt;BR /&gt;He will get correct output only when he does &lt;BR /&gt;&lt;BR /&gt;1. ps -ef|grep 'tgu*' &lt;BR /&gt;2. Go to some other directory and execute grep 'tgu*' where there are no files that are starting with tgu*&lt;BR /&gt;3. The rocking way of using UNIX95&lt;BR /&gt;&lt;BR /&gt;-Sri</description>
      <pubDate>Sun, 19 Aug 2001 07:02:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/2566792#M30061</guid>
      <dc:creator>Sridhar Bhaskarla</dc:creator>
      <dc:date>2001-08-19T07:02:51Z</dc:date>
    </item>
    <item>
      <title>Re: grep question ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/2566793#M30062</link>
      <description>Hi&lt;BR /&gt;   To remove the grep process being displayed so&lt;BR /&gt;&lt;BR /&gt;ps -ef | grep [t]gu&lt;BR /&gt;   &lt;BR /&gt;     with this we need not use grep -v grep&lt;BR /&gt;&lt;BR /&gt;...BPK...</description>
      <pubDate>Sun, 19 Aug 2001 13:07:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/2566793#M30062</guid>
      <dc:creator>Praveen Bezawada</dc:creator>
      <dc:date>2001-08-19T13:07:28Z</dc:date>
    </item>
    <item>
      <title>Re: grep question ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/2566794#M30063</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I like Bill's solution but the "Key" is that the process you are looking for should be the basename.&lt;BR /&gt;&lt;BR /&gt;for example if you have a process called "tgu tgu_stats"&lt;BR /&gt;executing UNIX95= ps -fC tgu_stats will not return any output, where as UNIX95= ps -fC tgu, will return the desired output.&lt;BR /&gt;&lt;BR /&gt;But my suggestion Richard is to avoid using * when grepping for anything and always enclose in ' ' to avoid shell misinterpretation.&lt;BR /&gt;&lt;BR /&gt;-Regards&lt;BR /&gt;I am RU</description>
      <pubDate>Sun, 19 Aug 2001 16:14:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-question/m-p/2566794#M30063</guid>
      <dc:creator>linuxfan</dc:creator>
      <dc:date>2001-08-19T16:14:18Z</dc:date>
    </item>
  </channel>
</rss>

