<?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: How to grep the correct pattern? in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519346#M889265</link>
    <description>Use:&lt;BR /&gt;while read ipaddr &lt;BR /&gt;do &lt;BR /&gt;&lt;BR /&gt;echo $(grep "$ipaddr$" /tmp/ipaddr.txt) &lt;BR /&gt;done &lt;BR /&gt;federico</description>
    <pubDate>Fri, 20 Apr 2001 05:13:56 GMT</pubDate>
    <dc:creator>federico_3</dc:creator>
    <dc:date>2001-04-20T05:13:56Z</dc:date>
    <item>
      <title>How to grep the correct pattern?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519342#M889261</link>
      <description>I am writing a script to capture all the current users that have established network connection and we have a static ip address list from which we can tell who is using which ip address. But when I grep "128.188.3.15" it come out all like "128.188.3.150, 3.151,3.152,...",  May I know how to correct it?  The script is shown below,&lt;BR /&gt;&lt;BR /&gt;netstat -n|grep "^tcp"|grep 128|awk '{print $5}'|sed "s/\.[0-9][0-9]*$//" |sort&lt;BR /&gt;-u &amp;gt;/tmp/tmpipaddr.lst&lt;BR /&gt;while read ipaddr&lt;BR /&gt;do&lt;BR /&gt;#   ipaddr="$ipaddr "   ;This line does not help&lt;BR /&gt;   echo $(grep "$ipaddr "  /tmp/ipaddr.txt)&lt;BR /&gt;done</description>
      <pubDate>Fri, 20 Apr 2001 02:29:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519342#M889261</guid>
      <dc:creator>Rashid Ali</dc:creator>
      <dc:date>2001-04-20T02:29:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to grep the correct pattern?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519343#M889262</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;One easy way to avoid the search string being interpreted as a substring is to add a space behind your search string ie.&lt;BR /&gt;&lt;BR /&gt;# netstat -n|grep "128.188.3.15 "&lt;BR /&gt;&lt;BR /&gt;instead of&lt;BR /&gt;&lt;BR /&gt;# netstat -n|grep "128.188.3.15"&lt;BR /&gt;&lt;BR /&gt;Similarly, in your search pattern (eg. sed), include the space at the end of your pattern for searching.&lt;BR /&gt;&lt;BR /&gt;Hope this helps. Regards.&lt;BR /&gt;&lt;BR /&gt;Steven Sim Kok Leong&lt;BR /&gt;Brainbench MVP for Unix Admin&lt;BR /&gt;&lt;A href="http://www.brainbench.com" target="_blank"&gt;http://www.brainbench.com&lt;/A&gt;</description>
      <pubDate>Fri, 20 Apr 2001 02:36:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519343#M889262</guid>
      <dc:creator>Steven Sim Kok Leong</dc:creator>
      <dc:date>2001-04-20T02:36:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to grep the correct pattern?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519344#M889263</link>
      <description>This script will work, if you use the print commands in the awk statement as follows,...&lt;BR /&gt;&lt;BR /&gt;awk { print $5" " }&lt;BR /&gt;&lt;BR /&gt;Then when you grep for $ipaddr" ", the space character will identify the end of significant data.&lt;BR /&gt;&lt;BR /&gt;Hope this helps, FRED</description>
      <pubDate>Fri, 20 Apr 2001 02:40:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519344#M889263</guid>
      <dc:creator>FRED Dennison</dc:creator>
      <dc:date>2001-04-20T02:40:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to grep the correct pattern?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519345#M889264</link>
      <description>I believed you have not understand what I want.&lt;BR /&gt;Actually In my script, it is the command "echo $(grep "$ipaddr " /tmp/ipaddr.txt)"  that won't work when searching patterns like "128.188.3.15" in a file /tmp/ipaddr.txt which contains the mapping of ip address and user name,  because this will also get all other users info for ip addresses such as "128.188.3.150", "128.188.3.151",etc.  I tried to append one space behind the variable $ipaddr but it didn't work. Is there any negative function to filter out some paticular patterns such as "$ipaddr[!0-9]" or "$ipaddr[~0-9]" ,  so that it can only grep a uniq user info with the required ip address?  &lt;BR /&gt;&lt;BR /&gt;I think one of the reason could be that there is some tab/control character behind the ip address instead of space character in file ipaddr.txt.   SO how should I pre-process this file before I can run grep "128.188.3.15 " ?&lt;BR /&gt;again, how can I apply this rule when the pattern to be searched in grep is assigned to a variable called $ipaddr ?  Should it be grep "$ipaddr " /tmp/ipaddr.txt?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;</description>
      <pubDate>Fri, 20 Apr 2001 04:45:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519345#M889264</guid>
      <dc:creator>Rashid Ali</dc:creator>
      <dc:date>2001-04-20T04:45:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to grep the correct pattern?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519346#M889265</link>
      <description>Use:&lt;BR /&gt;while read ipaddr &lt;BR /&gt;do &lt;BR /&gt;&lt;BR /&gt;echo $(grep "$ipaddr$" /tmp/ipaddr.txt) &lt;BR /&gt;done &lt;BR /&gt;federico</description>
      <pubDate>Fri, 20 Apr 2001 05:13:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519346#M889265</guid>
      <dc:creator>federico_3</dc:creator>
      <dc:date>2001-04-20T05:13:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to grep the correct pattern?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519347#M889266</link>
      <description>I wrote it so:&lt;BR /&gt;&lt;BR /&gt;                                                                                       netstat -n | awk ' $1 !="tcp"{ next}                                             { if ( $4 ~ "\.23$") p=1; else  if ( $4 ~ "\.1521$") p=2 ;else  p=3}                                               $4 ~ "xx\.xxx\.xx\.x1\." { inet[p]+=1  ;next }  ...&lt;BR /&gt;&lt;BR /&gt;                                                                             &lt;BR /&gt;</description>
      <pubDate>Fri, 20 Apr 2001 10:49:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519347#M889266</guid>
      <dc:creator>Carlos Fernandez Riera</dc:creator>
      <dc:date>2001-04-20T10:49:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to grep the correct pattern?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519348#M889267</link>
      <description>for ipaddr in 'cat /tmp/tmpipaddr' &lt;BR /&gt; do &lt;BR /&gt;grep "$ipaddr\$" /tmp/ipaddr.txt &lt;BR /&gt;done</description>
      <pubDate>Fri, 20 Apr 2001 13:14:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519348#M889267</guid>
      <dc:creator>Vincenzo Restuccia</dc:creator>
      <dc:date>2001-04-20T13:14:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to grep the correct pattern?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519349#M889268</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;   To grep for 128.188.3.15 i am giving you a simple eg which will grep only this ip and only this.&lt;BR /&gt;&lt;BR /&gt;#netstat -n | grep tcp | grep 128 | \ awk '{print $5}' | awk -F"." '{if ($4 == 15) \ print $0}'&lt;BR /&gt;&lt;BR /&gt;Hope this helps.&lt;BR /&gt;</description>
      <pubDate>Fri, 20 Apr 2001 17:06:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519349#M889268</guid>
      <dc:creator>Rajeev Tyagi</dc:creator>
      <dc:date>2001-04-20T17:06:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to grep the correct pattern?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519350#M889269</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Without going deeply into the whole problem, if you want to grep 128.188.3.15 only, not 128.188.3.150 and so on, try simply&lt;BR /&gt;&lt;BR /&gt;grep 128.188.3.15[^1-90]&lt;BR /&gt;&lt;BR /&gt;Of course you can do it the same also in the case when the pattern is given as reference to the value of some variable.&lt;BR /&gt;&lt;BR /&gt;Hope this helps.</description>
      <pubDate>Fri, 20 Apr 2001 21:28:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519350#M889269</guid>
      <dc:creator>Wieslaw Krajewski</dc:creator>
      <dc:date>2001-04-20T21:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to grep the correct pattern?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519351#M889270</link>
      <description>$ipaddr$ or $ipaddr\$ only matches those patterns that are the end of one line.  In my case, it is not necessary true.  I prefer "grep 128.188.3.15[^1-90]" ( [^1-90]" can be written as [^0-9] ? )  to rule out other possibilities.  &lt;BR /&gt;&lt;BR /&gt;Attached are two files j1 and j2, if you ftp these two files to unix and run "cat", the contents are the same but only grep "3.15 " j2 can work, grep "3.15 " j1 cannot.  How come like that?  How can I automatically convert j1 into j2?</description>
      <pubDate>Sat, 21 Apr 2001 02:20:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519351#M889270</guid>
      <dc:creator>Rashid Ali</dc:creator>
      <dc:date>2001-04-21T02:20:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to grep the correct pattern?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519352#M889271</link>
      <description>Here is j2.  Because one message can only have one attachment file.</description>
      <pubDate>Sat, 21 Apr 2001 02:22:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519352#M889271</guid>
      <dc:creator>Rashid Ali</dc:creator>
      <dc:date>2001-04-21T02:22:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to grep the correct pattern?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519353#M889272</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;In j1 file after 3.15 you have &lt;TAB&gt; wheras in j2 there are simply spaces.&lt;BR /&gt;Can check this just by&lt;BR /&gt;&lt;BR /&gt;grep "3.15&lt;TAB&gt;" j1&lt;BR /&gt;&lt;BR /&gt;grep "3.15&lt;TAB&gt;" j2&lt;BR /&gt;&lt;BR /&gt;where &lt;TAB&gt; corresponds to pressing the Tab key.&lt;BR /&gt;&lt;BR /&gt;As concerns convertion one file into another try sed or awk vommands.&lt;BR /&gt;&lt;BR /&gt;Good Luck&lt;/TAB&gt;&lt;/TAB&gt;&lt;/TAB&gt;&lt;/TAB&gt;</description>
      <pubDate>Sat, 21 Apr 2001 14:13:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519353#M889272</guid>
      <dc:creator>Wieslaw Krajewski</dc:creator>
      <dc:date>2001-04-21T14:13:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to grep the correct pattern?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519354#M889273</link>
      <description>It seems using sed 's/\009/\020/g' j1&amp;gt;j3 to convert tab into space cannot work. How should I issue the command?</description>
      <pubDate>Sun, 22 Apr 2001 23:04:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519354#M889273</guid>
      <dc:creator>Rashid Ali</dc:creator>
      <dc:date>2001-04-22T23:04:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to grep the correct pattern?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519355#M889274</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;So, try the following&lt;BR /&gt;&lt;BR /&gt;tr "&lt;TAB&gt;" "&lt;SPACE&gt; " &amp;lt; j1 &amp;gt; j3&lt;BR /&gt;&lt;BR /&gt;where &lt;TAB&gt; means pressing the Tab key and &lt;SPACE&gt; means pressing space key.&lt;BR /&gt;&lt;BR /&gt;It works, I am sure.&lt;/SPACE&gt;&lt;/TAB&gt;&lt;/SPACE&gt;&lt;/TAB&gt;</description>
      <pubDate>Mon, 23 Apr 2001 05:39:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519355#M889274</guid>
      <dc:creator>Wieslaw Krajewski</dc:creator>
      <dc:date>2001-04-23T05:39:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to grep the correct pattern?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519356#M889275</link>
      <description>Hi.&lt;BR /&gt;I've got to say I could not repeat the functionality of your script.  However, if I understand the problem it is in the line&lt;BR /&gt;grep $ipaddr /tmp/ipaddr.txt&lt;BR /&gt;try&lt;BR /&gt;grep -x $ipaddr /tmp/ipaddr.txt&lt;BR /&gt;if you have a file /tmp/file.txt &lt;BR /&gt;15&lt;BR /&gt;150&lt;BR /&gt;grep 15 /tmp/file.txt&lt;BR /&gt;15&lt;BR /&gt;150&lt;BR /&gt;grep -x 15 /tmp/file.txt&lt;BR /&gt;15</description>
      <pubDate>Mon, 23 Apr 2001 07:42:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519356#M889275</guid>
      <dc:creator>Tim D Fulford</dc:creator>
      <dc:date>2001-04-23T07:42:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to grep the correct pattern?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519357#M889276</link>
      <description>I think I have got the script you want&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;netstat -n | grep "^tcp" | awk '$4~/158/ || $5~/158/ {print $5}' | sed "s/\.[0-9][0-9]*$//" | sort -u &amp;gt; /tmp/tmpipaddr.lst&lt;BR /&gt;&lt;BR /&gt;for ipaddr in $(cat /tmp/tmpipaddr.lst)&lt;BR /&gt;do&lt;BR /&gt;      grep -x $ipaddr /tmp/ipaddr.txt&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;I changed the grep to an awk statement in the first line and got rid of the echo $(...) as it just issues a balnk line for each null find.&lt;BR /&gt;&lt;BR /&gt;I hope this helps and reduces the scripts complexity.&lt;BR /&gt;&lt;BR /&gt;Tim</description>
      <pubDate>Mon, 23 Apr 2001 09:29:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519357#M889276</guid>
      <dc:creator>Tim D Fulford</dc:creator>
      <dc:date>2001-04-23T09:29:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to grep the correct pattern?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519358#M889277</link>
      <description>grep -x is definitely not applicable to my case here since there is other user info besides ip address in ipaddr.txt.&lt;BR /&gt;Wieslaw's solution is working fine but I was wondering whether I can express it in binary format such as sed 's/\009/\020/g' j1&amp;gt;j3 or &lt;BR /&gt;tr "\009" "\020" &lt;J1&gt;j3, so that I don't need to press &lt;TAB&gt; or &lt;SPACE&gt;.   Anybody knows how to do that?&lt;BR /&gt;&lt;/SPACE&gt;&lt;/TAB&gt;&lt;/J1&gt;</description>
      <pubDate>Tue, 24 Apr 2001 00:34:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-grep-the-correct-pattern/m-p/2519358#M889277</guid>
      <dc:creator>Rashid Ali</dc:creator>
      <dc:date>2001-04-24T00:34:28Z</dc:date>
    </item>
  </channel>
</rss>

