<?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 awk query in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/4796320#M641444</link>
    <description>Hi Admins,&lt;BR /&gt;&lt;BR /&gt;Please explain about NF and NR variables with awk.&lt;BR /&gt;As per my understanding NF stands for last field of the file.&lt;BR /&gt;&lt;BR /&gt;#bdf|awk '{print $NR}'&lt;BR /&gt;Filesystem&lt;BR /&gt;2097152&lt;BR /&gt;341768&lt;BR /&gt;2294632&lt;BR /&gt;67%&lt;BR /&gt;/tmp&lt;BR /&gt;&lt;BR /&gt;Please explain the output of above code.&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;himacs&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Tue, 07 Jun 2011 11:11:30 GMT</pubDate>
    <dc:creator>himacs</dc:creator>
    <dc:date>2011-06-07T11:11:30Z</dc:date>
    <item>
      <title>awk query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/4796320#M641444</link>
      <description>Hi Admins,&lt;BR /&gt;&lt;BR /&gt;Please explain about NF and NR variables with awk.&lt;BR /&gt;As per my understanding NF stands for last field of the file.&lt;BR /&gt;&lt;BR /&gt;#bdf|awk '{print $NR}'&lt;BR /&gt;Filesystem&lt;BR /&gt;2097152&lt;BR /&gt;341768&lt;BR /&gt;2294632&lt;BR /&gt;67%&lt;BR /&gt;/tmp&lt;BR /&gt;&lt;BR /&gt;Please explain the output of above code.&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;himacs&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 07 Jun 2011 11:11:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/4796320#M641444</guid>
      <dc:creator>himacs</dc:creator>
      <dc:date>2011-06-07T11:11:30Z</dc:date>
    </item>
    <item>
      <title>Re: awk query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/4796321#M641445</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;In 'awk' the builtin variable 'NF' is the number of fields in a record (line) based on splitting the record into fields based on the record separator (by default, whitespace).&lt;BR /&gt;&lt;BR /&gt;The 'NR' variable is the number of the record (line) where a record is defined by the record separator (by default, a newline).&lt;BR /&gt;&lt;BR /&gt;In the example you show, you asked 'awk' to print the *field* represented by the *record number* --- an odd, and probably wrong choice.&lt;BR /&gt;&lt;BR /&gt;If you wanted the mount point (the last field) you would have written:&lt;BR /&gt;&lt;BR /&gt;# bdf|awk '{print $NF}'&lt;BR /&gt;&lt;BR /&gt;To skip the header line from 'bdf' you could do:&lt;BR /&gt;&lt;BR /&gt;# bdf|awk 'NR&amp;gt;1 {print $NF}'&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 07 Jun 2011 11:22:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/4796321#M641445</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-06-07T11:22:45Z</dc:date>
    </item>
    <item>
      <title>Re: awk query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/4796322#M641446</link>
      <description>Hi JRF,&lt;BR /&gt;&lt;BR /&gt;Thanks for the response.&lt;BR /&gt;&lt;BR /&gt;Can we print previous date using awk..&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;himacs</description>
      <pubDate>Tue, 07 Jun 2011 11:29:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/4796322#M641446</guid>
      <dc:creator>himacs</dc:creator>
      <dc:date>2011-06-07T11:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: awk query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/4796323#M641447</link>
      <description>Hi ,&lt;BR /&gt;&lt;BR /&gt;Ok,i can print current date as below&lt;BR /&gt;&lt;BR /&gt;#date +%d-%m-%Y&lt;BR /&gt;07-06-2011&lt;BR /&gt;&lt;BR /&gt;But how to print previous date 06-06-2011.&lt;BR /&gt;&lt;BR /&gt;Regards/himacs&lt;BR /&gt;</description>
      <pubDate>Tue, 07 Jun 2011 11:44:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/4796323#M641447</guid>
      <dc:creator>himacs</dc:creator>
      <dc:date>2011-06-07T11:44:28Z</dc:date>
    </item>
    <item>
      <title>Re: awk query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/4796324#M641448</link>
      <description>HI (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; Can we print previous date using awk..&lt;BR /&gt;&lt;BR /&gt;The HP-UX supplied 'awk' lacks some of the nice enhancements of GNU 'awk'.  In either, you can call an external command ('date' for example) and in the GNU version you have 'systime()' and 'strftime' (the former to return Epoch seconds; the later to format timestamps).&lt;BR /&gt;&lt;BR /&gt;If I understand you question, correctly, though, you need to use Perl.&lt;BR /&gt;&lt;BR /&gt;I'm coping to copy-and-paste two responses I offered to another member in an earlier thread:&lt;BR /&gt;&lt;BR /&gt;You might note that by using Perl and the 'strftime' function you can choose any date format you want. The format directives are equivalent to those you are familiar with in the 'date' command. Of course, see too the manpages for 'strftime(3C)'. For example:&lt;BR /&gt;&lt;BR /&gt;Find the date 2-days ago from today:&lt;BR /&gt;&lt;BR /&gt;# perl -MPOSIX -le 'print strftime "%d %b",localtime(time-(60*60*24*2))'&lt;BR /&gt;05 Jun&lt;BR /&gt;&lt;BR /&gt;# perl -MPOSIX -le 'print strftime "%m/%d/%Y",localtime(time-(60*60*24*2))'&lt;BR /&gt;06/05/2011&lt;BR /&gt;&lt;BR /&gt;You could also use this to find a date n-days from a specific starting date:&lt;BR /&gt;&lt;BR /&gt;# cat ./fromwhen&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;use POSIX qw(strftime);&lt;BR /&gt;use Time::Local;&lt;BR /&gt;my $date = shift or die "Date (YYYYMMDD) expected\n";&lt;BR /&gt;die "YYYMMDD expected\n" unless&lt;BR /&gt;    my ( $yyyy, $mm, $dd ) = ( $date =~ /(\d{4})(\d\d)(\d\d)/ );&lt;BR /&gt;my $when = shift or die "Number of days in past expected\n";&lt;BR /&gt;my $secs = timelocal(0, 0, 0, $dd, $mm-1,$yyyy );&lt;BR /&gt;print strftime "%Y/%m/%d\n",localtime($secs-(60*60*24*$when));&lt;BR /&gt;1;&lt;BR /&gt;&lt;BR /&gt;# ./fromwhen 20110607 7&lt;BR /&gt;2011/05/31&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 07 Jun 2011 11:54:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/4796324#M641448</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-06-07T11:54:40Z</dc:date>
    </item>
    <item>
      <title>Re: awk query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/4796325#M641449</link>
      <description>Hi JRF,&lt;BR /&gt;&lt;BR /&gt;Thanks for the nice reply.But m not familiar with perl.&lt;BR /&gt;&lt;BR /&gt;#date +%d" "%m" "%Y|awk '{print '$1=$1-1',$2,$3}'&lt;BR /&gt;sh: 1: Parameter not set.&lt;BR /&gt;&lt;BR /&gt;As expected ended up with error.Is there any option to replace '$1=$1-1' field..&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;himacs</description>
      <pubDate>Tue, 07 Jun 2011 11:59:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/4796325#M641449</guid>
      <dc:creator>himacs</dc:creator>
      <dc:date>2011-06-07T11:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: awk query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/4796326#M641450</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;I should clarify that with GNU 'awk' you could with little effort compute a timestamp n-days (or hours, etc.) before or after the current time in Epoch seconds with 'systime'.  Then, simply use 'strftime' to format it into human-readable values.  This would offer you something akin to the Perl script I offered.  You can install GNU 'awk' from here:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://hpux.connect.org.uk/hppd/hpux/Gnu/gawk-3.1.8/" target="_blank"&gt;http://hpux.connect.org.uk/hppd/hpux/Gnu/gawk-3.1.8/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 07 Jun 2011 12:04:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/4796326#M641450</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-06-07T12:04:35Z</dc:date>
    </item>
    <item>
      <title>Re: awk query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/4796327#M641451</link>
      <description>Hi JRF,&lt;BR /&gt;&lt;BR /&gt;Below code prints previous date.&lt;BR /&gt;&lt;BR /&gt;#date +%d" "%m" "%Y&lt;BR /&gt;07 06 2011&lt;BR /&gt;#date +%d" "%m" "%Y|awk '$1=$1-1'&lt;BR /&gt;6 06 2011&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;himacs&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 07 Jun 2011 12:08:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/4796327#M641451</guid>
      <dc:creator>himacs</dc:creator>
      <dc:date>2011-06-07T12:08:35Z</dc:date>
    </item>
    <item>
      <title>Re: awk query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/4796328#M641452</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; date +%d" "%m" "%Y|awk '{print '$1=$1-1',$2,$3}'&lt;BR /&gt;&lt;BR /&gt;...should have been:&lt;BR /&gt;&lt;BR /&gt;# date "+%d %m %Y"|awk '{print ($1-1),$2,$3}'&lt;BR /&gt;6 06 2011&lt;BR /&gt;&lt;BR /&gt;...but you are sliding down a slippery slope.  What happens when the day of the month is one (1)?  Your code fails.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Tue, 07 Jun 2011 12:10:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-query/m-p/4796328#M641452</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-06-07T12:10:36Z</dc:date>
    </item>
  </channel>
</rss>

