<?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 to Calculate help in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-calculate-help/m-p/3332385#M874089</link>
    <description>Thanks all for the help.&lt;BR /&gt;&lt;BR /&gt;Victor's "expr" works great.  Hein's "awk" is very great structually speaking.  But awk runs for 7 seconds while expr way runs 2 seconds.&lt;BR /&gt;&lt;BR /&gt;Please see the followings:&lt;BR /&gt;&lt;BR /&gt;1)&lt;BR /&gt;-----------------&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;LOG=/disk1/abc.log&lt;BR /&gt;&lt;BR /&gt;curr_no=`wc -l $LOG|awk '{print $1}'`&lt;BR /&gt;start_no=`expr $curr_no - 900`&lt;BR /&gt;&lt;BR /&gt;sed -n "$start_no,$curr_no p" $LOG |more&lt;BR /&gt;------------------&lt;BR /&gt;&lt;BR /&gt;2)&lt;BR /&gt;*******************&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;LOG=/disk1/abc.log&lt;BR /&gt;&lt;BR /&gt;awk -v W=900 '{line[i++%W]=$0} END {j=i-W;while (j&lt;I&gt;| more&lt;BR /&gt;********************&lt;BR /&gt;&lt;BR /&gt;Again, thanks a lot!&lt;BR /&gt;&lt;BR /&gt;&lt;/I&gt;</description>
    <pubDate>Thu, 15 Jul 2004 16:26:43 GMT</pubDate>
    <dc:creator>Steven Chen_1</dc:creator>
    <dc:date>2004-07-15T16:26:43Z</dc:date>
    <item>
      <title>Script to Calculate help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-calculate-help/m-p/3332380#M874084</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I am stuck with how to go through the calculation to read 900 lines out of a log file.&lt;BR /&gt;&lt;BR /&gt;Due to the tail command only getting 20k of lines, I need about 900 lines to monitor what's going on.   Therefore I have one script as follows:&lt;BR /&gt;&lt;BR /&gt;---------------------------&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;LOG=/disk1/abc.log&lt;BR /&gt;&lt;BR /&gt;curr_no=`wc -l $LOG|awk '{print $1}'`&lt;BR /&gt;start_no=900&lt;BR /&gt;&lt;BR /&gt;sed -n '$curr_no - $start_no,/$curr_no/p' abc.log&amp;gt;a1&lt;BR /&gt;---------------------------&lt;BR /&gt;&lt;BR /&gt;curr_no is the total number of lines on abc.log.&lt;BR /&gt;start_no is 900 lines.&lt;BR /&gt;$curr_no - $start_no is the difference of total-900.&lt;BR /&gt;&lt;BR /&gt;I don't know how to convert string back to number, as "$curr_no - $start_no" is getting string only.&lt;BR /&gt;&lt;BR /&gt;Hope someone help, or give some other direction.&lt;BR /&gt;&lt;BR /&gt;Very appreciated.&lt;BR /&gt;&lt;BR /&gt;Steven</description>
      <pubDate>Thu, 15 Jul 2004 07:51:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-calculate-help/m-p/3332380#M874084</guid>
      <dc:creator>Steven Chen_1</dc:creator>
      <dc:date>2004-07-15T07:51:03Z</dc:date>
    </item>
    <item>
      <title>Re: Script to Calculate help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-calculate-help/m-p/3332381#M874085</link>
      <description>Hi Steven,&lt;BR /&gt;&lt;BR /&gt;why don't you just use &lt;BR /&gt;&lt;BR /&gt;cat &lt;LOGFILE&gt;|while read line&lt;BR /&gt;do&lt;BR /&gt;&lt;YOUR_COMMANDS&gt;&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;HTH&lt;BR /&gt;&lt;BR /&gt;Franky&lt;/YOUR_COMMANDS&gt;&lt;/LOGFILE&gt;</description>
      <pubDate>Thu, 15 Jul 2004 07:58:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-calculate-help/m-p/3332381#M874085</guid>
      <dc:creator>Franky_1</dc:creator>
      <dc:date>2004-07-15T07:58:04Z</dc:date>
    </item>
    <item>
      <title>Re: Script to Calculate help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-calculate-help/m-p/3332382#M874086</link>
      <description>This is crude method, but will work.&lt;BR /&gt;&lt;BR /&gt;total= `nl "log_file"|tail -1|awk '{print $1}'`&lt;BR /&gt;#Display last 900 lines.&lt;BR /&gt;&lt;BR /&gt;start_line=$(($total-900))&lt;BR /&gt;&lt;BR /&gt;nl "log_file"|sed -n '/$start_line/,/$total/p;'&lt;BR /&gt;&lt;BR /&gt;Anil</description>
      <pubDate>Thu, 15 Jul 2004 07:59:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-calculate-help/m-p/3332382#M874086</guid>
      <dc:creator>RAC_1</dc:creator>
      <dc:date>2004-07-15T07:59:58Z</dc:date>
    </item>
    <item>
      <title>Re: Script to Calculate help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-calculate-help/m-p/3332383#M874087</link>
      <description>Hi Steven,&lt;BR /&gt;You would have to use the command expr,&lt;BR /&gt;do a man expr&lt;BR /&gt;&lt;BR /&gt;SOL=`expr $curr_no - $start_no`&lt;BR /&gt;&lt;BR /&gt;All the best&lt;BR /&gt;Victor</description>
      <pubDate>Thu, 15 Jul 2004 08:19:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-calculate-help/m-p/3332383#M874087</guid>
      <dc:creator>Victor BERRIDGE</dc:creator>
      <dc:date>2004-07-15T08:19:17Z</dc:date>
    </item>
    <item>
      <title>Re: Script to Calculate help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-calculate-help/m-p/3332384#M874088</link>
      <description>&lt;BR /&gt;If the file is really really big, such that wc takes significant time, then you just want to make a single pass. The following awk one liner will do just that.&lt;BR /&gt;&lt;BR /&gt;awk -v W=900 '{line[i++%W]=$0} END {j=i-W;while (j&lt;I&gt;&lt;BR /&gt;It works by putting every line seen in a 'circular' array of size W (900), overwritting as it needs to. At the end, print the lines in the array. The circular effect is achieved using a MODULUS (%) function.&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;With protection against short files...&lt;BR /&gt;&lt;BR /&gt;awk -v W=3 '{line[i++%W]=$0} END {j=(i&amp;gt;W)?i-W:i;while (j&lt;I&gt;&lt;BR /&gt;&lt;/I&gt;&lt;/I&gt;</description>
      <pubDate>Thu, 15 Jul 2004 08:34:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-calculate-help/m-p/3332384#M874088</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-07-15T08:34:16Z</dc:date>
    </item>
    <item>
      <title>Re: Script to Calculate help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-calculate-help/m-p/3332385#M874089</link>
      <description>Thanks all for the help.&lt;BR /&gt;&lt;BR /&gt;Victor's "expr" works great.  Hein's "awk" is very great structually speaking.  But awk runs for 7 seconds while expr way runs 2 seconds.&lt;BR /&gt;&lt;BR /&gt;Please see the followings:&lt;BR /&gt;&lt;BR /&gt;1)&lt;BR /&gt;-----------------&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;LOG=/disk1/abc.log&lt;BR /&gt;&lt;BR /&gt;curr_no=`wc -l $LOG|awk '{print $1}'`&lt;BR /&gt;start_no=`expr $curr_no - 900`&lt;BR /&gt;&lt;BR /&gt;sed -n "$start_no,$curr_no p" $LOG |more&lt;BR /&gt;------------------&lt;BR /&gt;&lt;BR /&gt;2)&lt;BR /&gt;*******************&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;LOG=/disk1/abc.log&lt;BR /&gt;&lt;BR /&gt;awk -v W=900 '{line[i++%W]=$0} END {j=i-W;while (j&lt;I&gt;| more&lt;BR /&gt;********************&lt;BR /&gt;&lt;BR /&gt;Again, thanks a lot!&lt;BR /&gt;&lt;BR /&gt;&lt;/I&gt;</description>
      <pubDate>Thu, 15 Jul 2004 16:26:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-calculate-help/m-p/3332385#M874089</guid>
      <dc:creator>Steven Chen_1</dc:creator>
      <dc:date>2004-07-15T16:26:43Z</dc:date>
    </item>
  </channel>
</rss>

