<?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 Script Problem - should be a simple one. in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-problem-should-be-a-simple-one/m-p/2941125#M930055</link>
    <description>Greeting One and All,&lt;BR /&gt;&lt;BR /&gt;I seem to have gone brain dead early this week.  I???m trying to write a quick script that pulls all the occurences of a word or number from a file.  Then extract the first word or number from that to echo along with the count.&lt;BR /&gt;.&lt;BR /&gt;so far, I find collect the occurrences by&lt;BR /&gt;somenum=$(cat basefile | grep ???keyword??? | awk ???{print $5}???)&lt;BR /&gt;to load the word or number into ???somenum???.&lt;BR /&gt;.&lt;BR /&gt;Then, to find the number of times the target word represented by $5 is&lt;BR /&gt;found, I use&lt;BR /&gt;another=$(cat basefile|grep ???keyword???|wc ???l)&lt;BR /&gt;because the target word is only on the same line as the keyword.&lt;BR /&gt;.&lt;BR /&gt;Now, I need to pull the first word or number from ???somenum???  so I can have a ---- &lt;BR /&gt;echo ???&lt;TARGET word=""&gt; has occurred $another times???&lt;BR /&gt;.&lt;BR /&gt;The $another, of course is the count and &lt;TARGET word=""&gt; is, again, represented by $5.&lt;BR /&gt;.&lt;BR /&gt;I can???t remember a way to pull the first occurrence of the target word from somenum.&lt;BR /&gt;.&lt;BR /&gt;Any help is greatly appreciated.  I???m very generous with points.&lt;BR /&gt;.&lt;BR /&gt;Paul Middleton &lt;BR /&gt;&lt;/TARGET&gt;&lt;/TARGET&gt;</description>
    <pubDate>Tue, 01 Apr 2003 19:11:12 GMT</pubDate>
    <dc:creator>Paul Middleton</dc:creator>
    <dc:date>2003-04-01T19:11:12Z</dc:date>
    <item>
      <title>Script Problem - should be a simple one.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-problem-should-be-a-simple-one/m-p/2941125#M930055</link>
      <description>Greeting One and All,&lt;BR /&gt;&lt;BR /&gt;I seem to have gone brain dead early this week.  I???m trying to write a quick script that pulls all the occurences of a word or number from a file.  Then extract the first word or number from that to echo along with the count.&lt;BR /&gt;.&lt;BR /&gt;so far, I find collect the occurrences by&lt;BR /&gt;somenum=$(cat basefile | grep ???keyword??? | awk ???{print $5}???)&lt;BR /&gt;to load the word or number into ???somenum???.&lt;BR /&gt;.&lt;BR /&gt;Then, to find the number of times the target word represented by $5 is&lt;BR /&gt;found, I use&lt;BR /&gt;another=$(cat basefile|grep ???keyword???|wc ???l)&lt;BR /&gt;because the target word is only on the same line as the keyword.&lt;BR /&gt;.&lt;BR /&gt;Now, I need to pull the first word or number from ???somenum???  so I can have a ---- &lt;BR /&gt;echo ???&lt;TARGET word=""&gt; has occurred $another times???&lt;BR /&gt;.&lt;BR /&gt;The $another, of course is the count and &lt;TARGET word=""&gt; is, again, represented by $5.&lt;BR /&gt;.&lt;BR /&gt;I can???t remember a way to pull the first occurrence of the target word from somenum.&lt;BR /&gt;.&lt;BR /&gt;Any help is greatly appreciated.  I???m very generous with points.&lt;BR /&gt;.&lt;BR /&gt;Paul Middleton &lt;BR /&gt;&lt;/TARGET&gt;&lt;/TARGET&gt;</description>
      <pubDate>Tue, 01 Apr 2003 19:11:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-problem-should-be-a-simple-one/m-p/2941125#M930055</guid>
      <dc:creator>Paul Middleton</dc:creator>
      <dc:date>2003-04-01T19:11:12Z</dc:date>
    </item>
    <item>
      <title>Re: Script Problem - should be a simple one.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-problem-should-be-a-simple-one/m-p/2941126#M930056</link>
      <description>Hi Paul:&lt;BR /&gt;&lt;BR /&gt;# N=`echo $somenum|awk '{print $1}'`&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 01 Apr 2003 19:44:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-problem-should-be-a-simple-one/m-p/2941126#M930056</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2003-04-01T19:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: Script Problem - should be a simple one.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-problem-should-be-a-simple-one/m-p/2941127#M930057</link>
      <description>Paul,&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;&lt;BR /&gt;countwords() {&lt;BR /&gt;  count=0&lt;BR /&gt;  for word in `cat $2`&lt;BR /&gt;  do&lt;BR /&gt;     if [[ $word = $1 ]]; then&lt;BR /&gt;        count=`expr $count +1`&lt;BR /&gt;     fi&lt;BR /&gt;  done&lt;BR /&gt;  echo $count&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;echo "the word $1 occurs `countwords $1 $2` times in file $2"&lt;BR /&gt;&lt;BR /&gt;exit 0&lt;BR /&gt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&lt;BR /&gt;Call as follows -&lt;BR /&gt;&lt;BR /&gt;count.sh &lt;WORD&gt; &lt;FILE&gt;&lt;BR /&gt;&lt;BR /&gt;grep is only going to return the number of lines with (any number of occurences) of the word. so although it would be a pain to check each and every word and arrive at the count, unless you use perl, it isn't going to be easy... &lt;BR /&gt;&lt;BR /&gt;and i don't know perl very well either. ;)&lt;BR /&gt;&lt;BR /&gt;- ramd.&lt;/FILE&gt;&lt;/WORD&gt;</description>
      <pubDate>Tue, 01 Apr 2003 20:08:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-problem-should-be-a-simple-one/m-p/2941127#M930057</guid>
      <dc:creator>Ramkumar Devanathan</dc:creator>
      <dc:date>2003-04-01T20:08:32Z</dc:date>
    </item>
    <item>
      <title>Re: Script Problem - should be a simple one.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-problem-should-be-a-simple-one/m-p/2941128#M930058</link>
      <description>A performance enhancement -&lt;BR /&gt;&lt;BR /&gt;for word in `cat $2` &lt;BR /&gt;&lt;BR /&gt;may be changed to &lt;BR /&gt;&lt;BR /&gt;for word in `cat $2 | grep $1` &lt;BR /&gt;&lt;BR /&gt;May be a good cut in iterations where there a lot of lines containing zero occurences of the word.&lt;BR /&gt;&lt;BR /&gt;- ramd.</description>
      <pubDate>Tue, 01 Apr 2003 20:28:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-problem-should-be-a-simple-one/m-p/2941128#M930058</guid>
      <dc:creator>Ramkumar Devanathan</dc:creator>
      <dc:date>2003-04-01T20:28:59Z</dc:date>
    </item>
    <item>
      <title>Re: Script Problem - should be a simple one.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-problem-should-be-a-simple-one/m-p/2941129#M930059</link>
      <description>James - I changed your input to N=($somenum|awk '{print $1}') to allow for the shell I'm using and it works great.&lt;BR /&gt;.&lt;BR /&gt;ramd - You gave me an idea for another project. I can use your input for reviewing older files on our systems.  Currently the script is just for new files being ftp'd in.  Now I can do both old and new a lot easier.&lt;BR /&gt;.&lt;BR /&gt;Thanks to both of you for your quick response.&lt;BR /&gt;.&lt;BR /&gt;Paul Middleton</description>
      <pubDate>Tue, 01 Apr 2003 21:24:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-problem-should-be-a-simple-one/m-p/2941129#M930059</guid>
      <dc:creator>Paul Middleton</dc:creator>
      <dc:date>2003-04-01T21:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: Script Problem - should be a simple one.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-problem-should-be-a-simple-one/m-p/2941130#M930060</link>
      <description>here is another way:&lt;BR /&gt;&lt;BR /&gt;&lt;YOURFILE&gt;&lt;/YOURFILE&gt;tr "[A-Z]" "[a-z]" |&lt;BR /&gt;#convert all uppercase to lowercase, use depending if you want to ignore capitialization&lt;BR /&gt;tr -cs "[a-z'0-9]" "\12" |&lt;BR /&gt;# replace all characters not a-z, ', or 0-9 with a newline, ie one word per line&lt;BR /&gt;sort| &lt;BR /&gt;#uniq expects sorted input&lt;BR /&gt;uniq -c |&lt;BR /&gt;#count number of times each word appears&lt;BR /&gt;sort +0nr +1d &lt;BR /&gt;# sort first from most to least frequent then alphabetically, or just grep for you word, grep $yourword&lt;BR /&gt;&lt;BR /&gt;the quick and dirty is&lt;BR /&gt;&lt;BR /&gt;num=$(&amp;lt;$yourfile |&lt;BR /&gt;tr -cs "[a-zA-Z0-9]" "\12" |&lt;BR /&gt;grep -xc $yourword |)&lt;BR /&gt;&lt;BR /&gt;print "$yourword occurs $num times."&lt;BR /&gt;&lt;BR /&gt;adjust your tr to include capitialization,digits,or punctuation that is allowed.</description>
      <pubDate>Tue, 01 Apr 2003 21:27:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-problem-should-be-a-simple-one/m-p/2941130#M930060</guid>
      <dc:creator>Curtis Larson_2</dc:creator>
      <dc:date>2003-04-01T21:27:43Z</dc:date>
    </item>
  </channel>
</rss>

