<?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 How to get output of a shell command within awk variable. in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-output-of-a-shell-command-within-awk-variable/m-p/4509625#M681190</link>
    <description>Please check the piece of code below,&lt;BR /&gt;&lt;BR /&gt;awk '{&lt;BR /&gt;dt="\"Oct 7 15:06:18\""&lt;BR /&gt;x="'"`date +%s -d $dt`"'"&lt;BR /&gt;printf "%s\n",x&lt;BR /&gt;}'&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;It is not working properly but I need similar solution. I would like to pass the dt varible to evaluate the epoch time and get it within the variable x.&lt;BR /&gt;</description>
    <pubDate>Wed, 07 Oct 2009 14:13:54 GMT</pubDate>
    <dc:creator>Sourav Basak</dc:creator>
    <dc:date>2009-10-07T14:13:54Z</dc:date>
    <item>
      <title>How to get output of a shell command within awk variable.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-output-of-a-shell-command-within-awk-variable/m-p/4509625#M681190</link>
      <description>Please check the piece of code below,&lt;BR /&gt;&lt;BR /&gt;awk '{&lt;BR /&gt;dt="\"Oct 7 15:06:18\""&lt;BR /&gt;x="'"`date +%s -d $dt`"'"&lt;BR /&gt;printf "%s\n",x&lt;BR /&gt;}'&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;It is not working properly but I need similar solution. I would like to pass the dt varible to evaluate the epoch time and get it within the variable x.&lt;BR /&gt;</description>
      <pubDate>Wed, 07 Oct 2009 14:13:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-output-of-a-shell-command-within-awk-variable/m-p/4509625#M681190</guid>
      <dc:creator>Sourav Basak</dc:creator>
      <dc:date>2009-10-07T14:13:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to get output of a shell command within awk variable.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-output-of-a-shell-command-within-awk-variable/m-p/4509626#M681191</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;In HP-UX or HP's 'awk' this isn't going to work.  You can, however, accomplish this easily in Perl:&lt;BR /&gt;&lt;BR /&gt;# perl -MTime::Local -le 'print +(timelocal(18,6,15,7,9,109))'&lt;BR /&gt;1254942378&lt;BR /&gt;&lt;BR /&gt;# perl -le 'print scalar localtime(1254942378)'&lt;BR /&gt;Wed Oct  7 15:06:18 2009&lt;BR /&gt;&lt;BR /&gt;The arguments to pass to timelocal() are:&lt;BR /&gt;&lt;BR /&gt;seconds, minutes, hours, month_day, month, year&lt;BR /&gt;&lt;BR /&gt;...in that order where:&lt;BR /&gt;&lt;BR /&gt;The 'month' is the calendar month number less one (1) and the year has 1900 subtracted from it.  That is, months are zer0-relative.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt; &lt;BR /&gt;</description>
      <pubDate>Wed, 07 Oct 2009 15:08:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-output-of-a-shell-command-within-awk-variable/m-p/4509626#M681191</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-10-07T15:08:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to get output of a shell command within awk variable.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-output-of-a-shell-command-within-awk-variable/m-p/4509627#M681192</link>
      <description>use the form&lt;BR /&gt;&lt;BR /&gt;"command" | getline &lt;VAR&gt;&lt;BR /&gt;&lt;BR /&gt;something along the lines of this should be close&lt;BR /&gt;&lt;BR /&gt;awk '{&lt;BR /&gt;dt="\"Oct 7 15:06:18\""&lt;BR /&gt;"'"`date +%s -d $dt`"'" | getline x&lt;BR /&gt;printf "%s\n",x&lt;BR /&gt;}'&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/VAR&gt;</description>
      <pubDate>Wed, 07 Oct 2009 15:11:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-output-of-a-shell-command-within-awk-variable/m-p/4509627#M681192</guid>
      <dc:creator>OldSchool</dc:creator>
      <dc:date>2009-10-07T15:11:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to get output of a shell command within awk variable.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-output-of-a-shell-command-within-awk-variable/m-p/4509628#M681193</link>
      <description>fyi...my original only works if the date command process the options the way you want it.&lt;BR /&gt;&lt;BR /&gt;and, the way you've got it, it would do it once per input line being processed,</description>
      <pubDate>Wed, 07 Oct 2009 15:15:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-output-of-a-shell-command-within-awk-variable/m-p/4509628#M681193</guid>
      <dc:creator>OldSchool</dc:creator>
      <dc:date>2009-10-07T15:15:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to get output of a shell command within awk variable.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-output-of-a-shell-command-within-awk-variable/m-p/4509629#M681194</link>
      <description>HI (again):&lt;BR /&gt;&lt;BR /&gt;In a GNU environment, this works:&lt;BR /&gt;&lt;BR /&gt;# cat ./epoch.awk&lt;BR /&gt;BEGIN{&lt;BR /&gt;    print "Evaluating: " dt&lt;BR /&gt;    "date +%s -d"  "\"" dt "\"" | getline x&lt;BR /&gt;    printf "%s\n",x&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;...run as:&lt;BR /&gt;&lt;BR /&gt;# awk -v dt="Oct 7 15:06:18" -f ./epoch.awk&lt;BR /&gt;Evaluating: Oct 7 15:06:18&lt;BR /&gt;1254942378&lt;BR /&gt;&lt;BR /&gt;# awk -v dt="Sep 8 21:46:39 2001" -f ./epoch.awk&lt;BR /&gt;Evaluating: Sep 8 21:46:39 2001&lt;BR /&gt;999999999&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 07 Oct 2009 17:28:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-output-of-a-shell-command-within-awk-variable/m-p/4509629#M681194</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-10-07T17:28:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to get output of a shell command within awk variable.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-output-of-a-shell-command-within-awk-variable/m-p/4509630#M681195</link>
      <description>This doesn't look like HP-UX code, no -d for date(1).&lt;BR /&gt;&lt;BR /&gt;Do you care that the date is evaluated outside before you run awk?&lt;BR /&gt;dt="Oct 7 15:06:18"&lt;BR /&gt;x=$(date +%s -d "$dt")&lt;BR /&gt;awk -v x="$x" 'BEGIN { print x }' /dev/null</description>
      <pubDate>Wed, 07 Oct 2009 22:17:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-output-of-a-shell-command-within-awk-variable/m-p/4509630#M681195</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-10-07T22:17:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to get output of a shell command within awk variable.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-output-of-a-shell-command-within-awk-variable/m-p/4509631#M681196</link>
      <description>Shalom,&lt;BR /&gt;&lt;BR /&gt;var=$(awk '{&lt;BR /&gt;dt="\"Oct 7 15:06:18\""&lt;BR /&gt;"'"`date +%s -d $dt`"'" | getline x&lt;BR /&gt;printf "%s\n",x&lt;BR /&gt;}')&lt;BR /&gt;&lt;BR /&gt;This will put the output of the command in brackets int he variable var&lt;BR /&gt;&lt;BR /&gt;The command itself needs some work.&lt;BR /&gt;&lt;BR /&gt;SEP</description>
      <pubDate>Wed, 07 Oct 2009 23:18:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-output-of-a-shell-command-within-awk-variable/m-p/4509631#M681196</guid>
      <dc:creator>Steven E. Protter</dc:creator>
      <dc:date>2009-10-07T23:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to get output of a shell command within awk variable.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-output-of-a-shell-command-within-awk-variable/m-p/4509632#M681197</link>
      <description>Thanks everybody for your reply, but my objective is bit different. &lt;BR /&gt;&lt;BR /&gt;I would like to filter syslog based on the timestamp. If I process syslog using awk, then the combination of $1,$2,$3 provide the timestamp. So I would like to create the timestamp for each record as, &lt;BR /&gt;        dt="\""$1" "$2" "$3"\""&lt;BR /&gt;Next I would like to convert it to epoch time as,&lt;BR /&gt;        x="'"`date +%s -d $dt`"'"&lt;BR /&gt;Next I would like to take decision based on the value of x.&lt;BR /&gt;But the problem is that since I am escaping to shell the awk variable is not available. So how can I pass it to shell. Is it possible to define dt as shell variable and dynamically assign the value from awk ?&lt;BR /&gt;&lt;BR /&gt;Thanks &lt;BR /&gt;Sourav &lt;BR /&gt;</description>
      <pubDate>Thu, 08 Oct 2009 05:38:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-output-of-a-shell-command-within-awk-variable/m-p/4509632#M681197</guid>
      <dc:creator>Sourav Basak</dc:creator>
      <dc:date>2009-10-08T05:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to get output of a shell command within awk variable.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-output-of-a-shell-command-within-awk-variable/m-p/4509633#M681198</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;Thanks everybody for your reply, but my objective is bit different.&lt;BR /&gt;&lt;BR /&gt;&amp;gt; You need to be more clear in your questions, then, at the onset.&lt;BR /&gt;&lt;BR /&gt;&amp;gt; ...Next I would like to convert it to epoch time...&lt;BR /&gt;&lt;BR /&gt;I showed you two ways to do that, using Perl and using a GNU 'date' command which offers the '-d' option.  HP-UX's 'date' does not have that ability.&lt;BR /&gt;&lt;BR /&gt;You can see a Perl solution in my post above on Oct 7, 2009 16:08:50 .  Using GNU's 'date' I showed you how your script could work by passing a string in my post dated Oct 7, 2009 18:28:57, above.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;...since I am escaping to shell the awk variable is not available. So how can I pass it to shell. Is it possible to define dt as shell variable and dynamically assign the value from awk ?&lt;BR /&gt;&lt;BR /&gt;OK, quite simply you can use this script:&lt;BR /&gt;&lt;BR /&gt;# cat ./epoch.awk&lt;BR /&gt;BEGIN{&lt;BR /&gt;"date +%s -d" "\"" dt "\"" | getline x&lt;BR /&gt;printf "%s\n",x&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;You can use it any of these ways:&lt;BR /&gt;&lt;BR /&gt;# EPOCH=$(awk -v dt="Sep 8 21:46:39 2001" -f ./epoch.awk)&lt;BR /&gt;# echo ${EPOCH}&lt;BR /&gt;999999999&lt;BR /&gt;&lt;BR /&gt;(or)&lt;BR /&gt;&lt;BR /&gt;# dt="Sep 8 21:46:39 2001"&lt;BR /&gt;# EPOCH=$(awk -v dt="${dt}" -f ./epoch.awk)&lt;BR /&gt;# echo ${EPOCH}&lt;BR /&gt;999999999&lt;BR /&gt;&lt;BR /&gt;Thus your shell script can pass a shell variable to 'awk' and receive the value of a shell variable from 'awk'.  Be sure to double quote your 'dt' variable when you pass it to 'awk' since you need to preserve the whitespaces it contains!&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 08 Oct 2009 11:06:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-get-output-of-a-shell-command-within-awk-variable/m-p/4509633#M681198</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-10-08T11:06:47Z</dc:date>
    </item>
  </channel>
</rss>

