<?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 count line in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/count-line/m-p/6225395#M496239</link>
    <description>&lt;P&gt;&lt;BR /&gt;I would like to have script to do it , please help .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is a log file , the sample is as below .&lt;/P&gt;&lt;P&gt;#vi log.txt&lt;BR /&gt;xxxx111xxxxxxxaaaxxx&lt;BR /&gt;xxxx111xxxxxxxxxbbbx&lt;BR /&gt;xxxxxxxxxxxxxxcccxxx&lt;BR /&gt;xxx111xxxxxxxxxxxxxx&lt;BR /&gt;xxxx111xxxxxxxaaaxxx&lt;BR /&gt;xxxx111xxxxxxxxxbbbx&lt;BR /&gt;xxxx111xxxxxxxcccxxx&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I want to count the occurence of a specific string in the log file .&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;the condition is where "111" AND the specific string ( eg. aaa , bbb , ccc ) is exist , then count how many lines have this two string at the same time .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To better for maintainence , there is a file to keep the string , the file content is as below .&lt;BR /&gt;#vi string.txt&lt;BR /&gt;aaa&lt;BR /&gt;bbb&lt;BR /&gt;ccc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As above ,&amp;nbsp;therefore , &amp;nbsp;the result should be as below.&lt;/P&gt;&lt;P&gt;there are 2 lines have both "111" and "aaa"&lt;BR /&gt;there are 2 lines have both "111" and "bbb"&lt;BR /&gt;there are 1 lines have both "111" and "ccc"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;explaination&lt;BR /&gt;=============&lt;/P&gt;&lt;P&gt;xxxx111xxxxxxxaaaxxx&amp;nbsp; ==&amp;gt; both "111" and "aaa" exist , count 1&lt;BR /&gt;xxxx111xxxxxxxxxbbbx&amp;nbsp; ==&amp;gt; both "111" and "bbb" exist , count 1 &amp;nbsp;&lt;BR /&gt;xxxxxxxxxxxxxxcccxxx&amp;nbsp; ==&amp;gt; only "ccc" exist&lt;BR /&gt;xxx111xxxxxxxxxxxxxx&amp;nbsp; ==&amp;gt; only "111" exist&lt;BR /&gt;xxxx111xxxxxxxaaaxxx&amp;nbsp; ==&amp;gt; both "111" and "aaa" exist , count 1&lt;BR /&gt;xxxx111xxxxxxxxxbbbx&amp;nbsp; ==&amp;gt; both "111" and "bbb" exist , count 1&lt;BR /&gt;xxxx111xxxxxxxcccxxx&amp;nbsp; ==&amp;gt; both "111" and "ccc" exist , count 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;therefore , we got the result&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;there are 2 lines have both "111" and "aaa"&lt;BR /&gt;there are 2 lines have both "111" and "bbb"&lt;BR /&gt;there are 1 lines have both "111" and "ccc"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;would advise how to write it ? thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 03 Oct 2013 08:30:28 GMT</pubDate>
    <dc:creator>2ne1Abcd</dc:creator>
    <dc:date>2013-10-03T08:30:28Z</dc:date>
    <item>
      <title>count line</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/count-line/m-p/6225395#M496239</link>
      <description>&lt;P&gt;&lt;BR /&gt;I would like to have script to do it , please help .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is a log file , the sample is as below .&lt;/P&gt;&lt;P&gt;#vi log.txt&lt;BR /&gt;xxxx111xxxxxxxaaaxxx&lt;BR /&gt;xxxx111xxxxxxxxxbbbx&lt;BR /&gt;xxxxxxxxxxxxxxcccxxx&lt;BR /&gt;xxx111xxxxxxxxxxxxxx&lt;BR /&gt;xxxx111xxxxxxxaaaxxx&lt;BR /&gt;xxxx111xxxxxxxxxbbbx&lt;BR /&gt;xxxx111xxxxxxxcccxxx&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I want to count the occurence of a specific string in the log file .&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;the condition is where "111" AND the specific string ( eg. aaa , bbb , ccc ) is exist , then count how many lines have this two string at the same time .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To better for maintainence , there is a file to keep the string , the file content is as below .&lt;BR /&gt;#vi string.txt&lt;BR /&gt;aaa&lt;BR /&gt;bbb&lt;BR /&gt;ccc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As above ,&amp;nbsp;therefore , &amp;nbsp;the result should be as below.&lt;/P&gt;&lt;P&gt;there are 2 lines have both "111" and "aaa"&lt;BR /&gt;there are 2 lines have both "111" and "bbb"&lt;BR /&gt;there are 1 lines have both "111" and "ccc"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;explaination&lt;BR /&gt;=============&lt;/P&gt;&lt;P&gt;xxxx111xxxxxxxaaaxxx&amp;nbsp; ==&amp;gt; both "111" and "aaa" exist , count 1&lt;BR /&gt;xxxx111xxxxxxxxxbbbx&amp;nbsp; ==&amp;gt; both "111" and "bbb" exist , count 1 &amp;nbsp;&lt;BR /&gt;xxxxxxxxxxxxxxcccxxx&amp;nbsp; ==&amp;gt; only "ccc" exist&lt;BR /&gt;xxx111xxxxxxxxxxxxxx&amp;nbsp; ==&amp;gt; only "111" exist&lt;BR /&gt;xxxx111xxxxxxxaaaxxx&amp;nbsp; ==&amp;gt; both "111" and "aaa" exist , count 1&lt;BR /&gt;xxxx111xxxxxxxxxbbbx&amp;nbsp; ==&amp;gt; both "111" and "bbb" exist , count 1&lt;BR /&gt;xxxx111xxxxxxxcccxxx&amp;nbsp; ==&amp;gt; both "111" and "ccc" exist , count 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;therefore , we got the result&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;there are 2 lines have both "111" and "aaa"&lt;BR /&gt;there are 2 lines have both "111" and "bbb"&lt;BR /&gt;there are 1 lines have both "111" and "ccc"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;would advise how to write it ? thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2013 08:30:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/count-line/m-p/6225395#M496239</guid>
      <dc:creator>2ne1Abcd</dc:creator>
      <dc:date>2013-10-03T08:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: count line</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/count-line/m-p/6225695#M496240</link>
      <description>&lt;P&gt;Have a look at this script:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# cat script.sh&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;for LTR in $(&amp;lt; string.txt)&lt;BR /&gt;do&lt;BR /&gt;COUNT=$(grep 111 log.txt | grep -c ${LTR})&lt;BR /&gt;echo "There are ${COUNT} lines with both 111 and ${LTR}"&lt;BR /&gt;done&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# ./script.sh&lt;BR /&gt;There are 2 lines with both 111 and aaa&lt;BR /&gt;There are 2 lines with both 111 and bbb&lt;BR /&gt;There are 1 lines with both 111 and ccc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2013 13:48:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/count-line/m-p/6225695#M496240</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2013-10-03T13:48:41Z</dc:date>
    </item>
    <item>
      <title>Re: count line</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/count-line/m-p/6226383#M496241</link>
      <description>&lt;P&gt;thanks reply ,&lt;/P&gt;&lt;P&gt;I have an additional request , if the string.txt is as below , there is another column in the file , seperate by space&lt;/P&gt;&lt;P&gt;#vi string.txt&lt;BR /&gt;aaa&amp;nbsp;&amp;nbsp; first line&lt;BR /&gt;bbb&amp;nbsp;&amp;nbsp; second line&lt;BR /&gt;ccc&amp;nbsp;&amp;nbsp; third line&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;if I would like the output is as below ( display the string of second column ) , how to make it ?&lt;/P&gt;&lt;P&gt;There are 2 lines with both 111 and first line&lt;BR /&gt;There are 2 lines with both 111 and second line&lt;BR /&gt;There are 1 lines with both 111 and third line&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Another question , if the no. of character in the column is different , if I use echo to change the display format to show the ${COUNT} output , then the output will not tidy due to the different no. of character&lt;/P&gt;&lt;P&gt;for example ,&lt;/P&gt;&lt;P&gt;#vi script.sh&lt;BR /&gt;for LTR in $(&amp;lt; string.txt)&lt;BR /&gt;do&lt;BR /&gt;COUNT=$(grep 111 log.txt | grep -c ${LTR})&lt;BR /&gt;second_column=...&lt;BR /&gt;echo ${second_column} ${COUNT}&lt;BR /&gt;done&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The output will be as below , as the no of character of second column is different , then the ${COUNT} is not tidy to display, how to make sure the ${COUNT} column is align ?&lt;BR /&gt;#script.sh&lt;BR /&gt;first line&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&lt;BR /&gt;second line&amp;nbsp;&amp;nbsp;&amp;nbsp;5&lt;BR /&gt;third line&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;2&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2013 03:37:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/count-line/m-p/6226383#M496241</guid>
      <dc:creator>2ne1Abcd</dc:creator>
      <dc:date>2013-10-04T03:37:39Z</dc:date>
    </item>
    <item>
      <title>Re: count line</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/count-line/m-p/6226461#M496242</link>
      <description>&lt;P&gt;&amp;gt;if the string.txt is as below, there is another column in the file&lt;/P&gt;&lt;P&gt;&amp;gt;if I would like the output is as below (display the string of second column)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What did you want to do with the second column?&amp;nbsp; Just print it but still search for the first column?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;while read LTR second; do&lt;BR /&gt;&amp;nbsp;&amp;nbsp; COUNT=$(grep 111 log.txt | grep -c ${LTR})&lt;BR /&gt;&amp;nbsp;&amp;nbsp; echo "There are ${COUNT} lines with both 111 and ${second}"&lt;BR /&gt;done &amp;lt; string.txt&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt; if I use echo to change the display format to show the ${COUNT} output , then the output will not tidy&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can do several things.&amp;nbsp; Put the count before the varying char column:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; echo "${COUNT} ${second_column}"&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;And if you think the number of chars in $COUNT will vary, you can&amp;nbsp; use typeset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; typeset -R5 COUNT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That way COUNT is always 5 wide and the number is right justified.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can also use typeset on second_column to set a fixed width:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; typeset -L20 second_column&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can also do the same things with printf(1):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; printf "%-20.20s %5d\n" $second_column $COUNT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This left justifies second_column in a 20 character field and truncates if longer than 20.&lt;/P&gt;&lt;P&gt;COUNT is right justified in a 5 character field.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2013 08:04:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/count-line/m-p/6226461#M496242</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2013-10-04T08:04:01Z</dc:date>
    </item>
  </channel>
</rss>

