<?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: script query in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-query/m-p/3672983#M798300</link>
    <description>&lt;BR /&gt;Muthukumar, before I use your following script:&lt;BR /&gt;&lt;BR /&gt;# awk '{ var=substr($1,0,6);print var; }' file1 | while read sname;&lt;BR /&gt;do&lt;BR /&gt;grep $sname file2 &amp;gt;&amp;gt; file3&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;can you please explain what the awk line is exactly doing? I am new to scripting and have no experience of awk.&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
    <pubDate>Mon, 21 Nov 2005 06:05:11 GMT</pubDate>
    <dc:creator>Ravinder Singh Gill</dc:creator>
    <dc:date>2005-11-21T06:05:11Z</dc:date>
    <item>
      <title>script query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-query/m-p/3672976#M798293</link>
      <description>fullnames are in file1. In file2 I have shortnames. What I am trying to do is match the shortnames in file2 to the first six characters of fullname in file1. I want to output the matched ones to file3. Why does the following not work?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;while read fullname&lt;BR /&gt;do&lt;BR /&gt;shortname=$ echo $fullname | cut -c1-5&lt;BR /&gt;grep $shortname file2&lt;BR /&gt;&lt;BR /&gt;if&lt;BR /&gt;[ $? = 0 ]&lt;BR /&gt;then&lt;BR /&gt;echo $fullname &amp;gt;&amp;gt; file3&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;done &amp;lt; file1&lt;BR /&gt;</description>
      <pubDate>Wed, 16 Nov 2005 12:21:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-query/m-p/3672976#M798293</guid>
      <dc:creator>Ravinder Singh Gill</dc:creator>
      <dc:date>2005-11-16T12:21:56Z</dc:date>
    </item>
    <item>
      <title>Re: script query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-query/m-p/3672977#M798294</link>
      <description>This line:&lt;BR /&gt;shortname=$ echo $fullname | cut -c1-5&lt;BR /&gt;&lt;BR /&gt;Should be this:&lt;BR /&gt;shortname=$(echo $fullname | cut -c1-5)&lt;BR /&gt;&lt;BR /&gt;Your 'if [ $? = 0 ]' needs to all be on one line as well.  I suspect it is in your script, but the Forums screwed it up when you posted it.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 16 Nov 2005 12:39:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-query/m-p/3672977#M798294</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2005-11-16T12:39:53Z</dc:date>
    </item>
    <item>
      <title>Re: script query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-query/m-p/3672978#M798295</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;try this:&lt;BR /&gt;&lt;BR /&gt;while read fullname&lt;BR /&gt;do&lt;BR /&gt;shortname=$( echo $fullname | cut -c1-5)&lt;BR /&gt;grep -q $shortname file2&lt;BR /&gt;&lt;BR /&gt;if [ $? = 0 ]&lt;BR /&gt;then&lt;BR /&gt;echo $fullname &amp;gt;&amp;gt;file3&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;done &amp;lt; file1&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;John K.&lt;BR /&gt;</description>
      <pubDate>Wed, 16 Nov 2005 12:46:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-query/m-p/3672978#M798295</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2005-11-16T12:46:04Z</dc:date>
    </item>
    <item>
      <title>Re: script query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-query/m-p/3672979#M798296</link>
      <description>IMHO...you can reverse the algorithm inside your script, search the shortnames in file2 to the fullnames in file1 w/o taking the  the first six characters of file1 into account. Something like...&lt;BR /&gt;&lt;BR /&gt;# cat file2 | while read shortname&lt;BR /&gt;&amp;gt; do&lt;BR /&gt;&amp;gt;   grep "^$shortname" file1 &amp;gt; file3&lt;BR /&gt;&amp;gt; done&lt;BR /&gt;&lt;BR /&gt;thanks!</description>
      <pubDate>Wed, 16 Nov 2005 15:42:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-query/m-p/3672979#M798296</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2005-11-16T15:42:22Z</dc:date>
    </item>
    <item>
      <title>Re: script query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-query/m-p/3672980#M798297</link>
      <description>Use as,&lt;BR /&gt;&lt;BR /&gt;# awk '{ var=substr($1,0,6);print var; }' file1 | while read sname;&lt;BR /&gt;do&lt;BR /&gt;   grep $sname file2 &amp;gt;&amp;gt; file3&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;hth.</description>
      <pubDate>Thu, 17 Nov 2005 01:30:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-query/m-p/3672980#M798297</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-11-17T01:30:51Z</dc:date>
    </item>
    <item>
      <title>Re: script query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-query/m-p/3672981#M798298</link>
      <description>Sandman,&lt;BR /&gt;&lt;BR /&gt;Your logic of,&lt;BR /&gt;&lt;BR /&gt;# cat file2 | while read shortname&lt;BR /&gt;&amp;gt; do&lt;BR /&gt;&amp;gt; grep "^$shortname" file1 &amp;gt; file3&lt;BR /&gt;&amp;gt; done&lt;BR /&gt;&lt;BR /&gt;is good. However with problem.&lt;BR /&gt;&lt;BR /&gt;# Problem 1:&lt;BR /&gt;&lt;BR /&gt;grep "^$shortname" file1 &amp;gt; file3&lt;BR /&gt;Change this to append mode as,&lt;BR /&gt;grep "^$shortname" file1 &amp;gt;&amp;gt; file3&lt;BR /&gt;&lt;BR /&gt;# Problem 2:&lt;BR /&gt;grep "^$shortname" file1&lt;BR /&gt;It will log file1 contents to file3. We can change as,&lt;BR /&gt;&lt;BR /&gt;grep -q '^$shortname" file1&lt;BR /&gt;[[ $? -eq 0 ]] &amp;amp;&amp;amp; echo $shortname &amp;gt;&amp;gt; file3&lt;BR /&gt;&lt;BR /&gt;# Problem 3:&lt;BR /&gt;&lt;BR /&gt;Change cat file2 to as,&lt;BR /&gt;&lt;BR /&gt;while ..&lt;BR /&gt;do&lt;BR /&gt;..&lt;BR /&gt;done &amp;lt; file&lt;BR /&gt;&lt;BR /&gt;Will be more good.&lt;BR /&gt;&lt;BR /&gt;# Use as,&lt;BR /&gt;&lt;BR /&gt;rm -f file3&lt;BR /&gt;while read shortname&lt;BR /&gt;do&lt;BR /&gt;  grep -q "^$shortname" file1&lt;BR /&gt;  [[ $? -eq 0 ]] &amp;amp;&amp;amp; echo "$shortname" &amp;gt;&amp;gt; file3&lt;BR /&gt;done &amp;lt; file2&lt;BR /&gt;&lt;BR /&gt;hth.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 17 Nov 2005 01:36:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-query/m-p/3672981#M798298</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-11-17T01:36:29Z</dc:date>
    </item>
    <item>
      <title>Re: script query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-query/m-p/3672982#M798299</link>
      <description>I tried Muthukumar's suggestion but file three was coming out blank.&lt;BR /&gt;&lt;BR /&gt;I tried Patrick Wallek's suggestion but no file3 was produced.</description>
      <pubDate>Mon, 21 Nov 2005 05:56:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-query/m-p/3672982#M798299</guid>
      <dc:creator>Ravinder Singh Gill</dc:creator>
      <dc:date>2005-11-21T05:56:47Z</dc:date>
    </item>
    <item>
      <title>Re: script query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-query/m-p/3672983#M798300</link>
      <description>&lt;BR /&gt;Muthukumar, before I use your following script:&lt;BR /&gt;&lt;BR /&gt;# awk '{ var=substr($1,0,6);print var; }' file1 | while read sname;&lt;BR /&gt;do&lt;BR /&gt;grep $sname file2 &amp;gt;&amp;gt; file3&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;can you please explain what the awk line is exactly doing? I am new to scripting and have no experience of awk.&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Mon, 21 Nov 2005 06:05:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-query/m-p/3672983#M798300</guid>
      <dc:creator>Ravinder Singh Gill</dc:creator>
      <dc:date>2005-11-21T06:05:11Z</dc:date>
    </item>
    <item>
      <title>Re: script query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-query/m-p/3672984#M798301</link>
      <description>Try and keep it simple and short:&lt;BR /&gt;&lt;BR /&gt;while read fullname&lt;BR /&gt;do&lt;BR /&gt; shortname=$(echo $fullname | cut -c1-5)&lt;BR /&gt; if (grep -i $shortname file2)&lt;BR /&gt; then&lt;BR /&gt;      echo $shortname &amp;gt;&amp;gt; file3&lt;BR /&gt; fi&lt;BR /&gt;done &amp;lt; file1 &lt;BR /&gt;&lt;BR /&gt;I supposed you wanted to output shortname to file3 and not fullname to file3 , as these&lt;BR /&gt;are already in file1 right !&lt;BR /&gt;</description>
      <pubDate>Mon, 21 Nov 2005 06:17:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-query/m-p/3672984#M798301</guid>
      <dc:creator>Frank de Vries</dc:creator>
      <dc:date>2005-11-21T06:17:35Z</dc:date>
    </item>
    <item>
      <title>Re: script query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-query/m-p/3672985#M798302</link>
      <description>I want to output fullname to file3, but only those fullnames which have a matching shortname existing in file2.</description>
      <pubDate>Mon, 21 Nov 2005 06:25:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-query/m-p/3672985#M798302</guid>
      <dc:creator>Ravinder Singh Gill</dc:creator>
      <dc:date>2005-11-21T06:25:08Z</dc:date>
    </item>
    <item>
      <title>Re: script query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-query/m-p/3672986#M798303</link>
      <description>Every shortname has a fullname, but not every fullname has a shortname, hence I wish to identify the appropriate fullnames for the shortnames (a few thousand) and put them in file3.</description>
      <pubDate>Mon, 21 Nov 2005 06:49:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-query/m-p/3672986#M798303</guid>
      <dc:creator>Ravinder Singh Gill</dc:creator>
      <dc:date>2005-11-21T06:49:02Z</dc:date>
    </item>
    <item>
      <title>Re: script query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-query/m-p/3672987#M798304</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;since none of your suggestions have produced the correct result, you should perhaps supply some authentic input material: one problem could be that a shortname, equal to the first 6 chars of a fullname, will have more than a single match in fullname, e.g.:&lt;BR /&gt;&lt;BR /&gt;file_of_fullnames&lt;BR /&gt;Stevens, Shaking&lt;BR /&gt;Stevenson, Robert Louis&lt;BR /&gt;&lt;BR /&gt;The shortname for both, "Steve" will have two hits - and they are a bit apart, literally speaking...&lt;BR /&gt;&lt;BR /&gt;Are the shortnames unique?&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;John K.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 21 Nov 2005 07:35:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-query/m-p/3672987#M798304</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2005-11-21T07:35:23Z</dc:date>
    </item>
    <item>
      <title>Re: script query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-query/m-p/3672988#M798305</link>
      <description>Hello Ravinder,&lt;BR /&gt;&lt;BR /&gt;Have you tried my suggestion? It does exactly what you're looking for:&lt;BR /&gt;&lt;BR /&gt;# cat file2 | while read shortname&lt;BR /&gt;&amp;gt; do&lt;BR /&gt;&amp;gt; grep "^$shortname" file1 &amp;gt;&amp;gt; file3&lt;BR /&gt;&amp;gt; done&lt;BR /&gt;&lt;BR /&gt;This will output only matching longnames into file3.&lt;BR /&gt;&lt;BR /&gt;hope it helps!!!</description>
      <pubDate>Mon, 21 Nov 2005 13:03:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-query/m-p/3672988#M798305</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2005-11-21T13:03:34Z</dc:date>
    </item>
    <item>
      <title>Re: script query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-query/m-p/3672989#M798306</link>
      <description>Ok,&lt;BR /&gt;I see what you mean:&lt;BR /&gt;This will do the trick for you:&lt;BR /&gt;&lt;BR /&gt;while read fullname&lt;BR /&gt;do&lt;BR /&gt;shortname=$(echo $fullname | cut -c1-5)&lt;BR /&gt;if (grep -i $shortname file2)&lt;BR /&gt;then&lt;BR /&gt;echo $fullname &amp;gt;&amp;gt; file3&lt;BR /&gt;fi&lt;BR /&gt;done &amp;lt; file1 &lt;BR /&gt;&lt;BR /&gt;good luck&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 23 Nov 2005 03:58:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-query/m-p/3672989#M798306</guid>
      <dc:creator>Frank de Vries</dc:creator>
      <dc:date>2005-11-23T03:58:35Z</dc:date>
    </item>
  </channel>
</rss>

