<?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: Capturing awk &amp;quot;system&amp;quot; command to awk variable? in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/capturing-awk-quot-system-quot-command-to-awk-variable/m-p/3365789#M97074</link>
    <description>Hi Ceesjan,&lt;BR /&gt;&lt;BR /&gt;How a dynamic string can be pushed in the command e.g. du &lt;FOLDER name=""&gt; -s ...&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Kuntal&lt;/FOLDER&gt;</description>
    <pubDate>Tue, 26 Dec 2006 21:39:08 GMT</pubDate>
    <dc:creator>Kuntal Roy</dc:creator>
    <dc:date>2006-12-26T21:39:08Z</dc:date>
    <item>
      <title>Capturing awk "system" command to awk variable?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/capturing-awk-quot-system-quot-command-to-awk-variable/m-p/3365784#M97069</link>
      <description>Within awk, there is the system() function that lets me run a system command.  However this only lets me capture the return code.&lt;BR /&gt;&lt;BR /&gt;How can I capture the output into an awk variable?  I know this can be done in perl etc, but I'm using awk, so...&lt;BR /&gt;&lt;BR /&gt;eg (in a simple case): -&lt;BR /&gt;&lt;BR /&gt;awk '{fred=`system("df $1")` ; split(fred,bill) ; print $1" uses "bill[4]" blocks."}' filesystems&lt;BR /&gt;&lt;BR /&gt;I know THIS example can be done in other ways, but it's taken as part of a larger context in awk which is why I need awk.&lt;BR /&gt;&lt;BR /&gt;Any ideas?</description>
      <pubDate>Thu, 26 Aug 2004 08:07:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/capturing-awk-quot-system-quot-command-to-awk-variable/m-p/3365784#M97069</guid>
      <dc:creator>Simon Hargrave</dc:creator>
      <dc:date>2004-08-26T08:07:23Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing awk "system" command to awk variable?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/capturing-awk-quot-system-quot-command-to-awk-variable/m-p/3365785#M97070</link>
      <description>You can use the "getline" function-&lt;BR /&gt; &lt;BR /&gt;"whoami" | getline&lt;BR /&gt; &lt;BR /&gt;Will execute "whoami" and put the result into $0 (and also parse for fields).&lt;BR /&gt; &lt;BR /&gt;"whoami" | getline myvar&lt;BR /&gt; &lt;BR /&gt;Will instead put the result into myvar.&lt;BR /&gt; &lt;BR /&gt;HTH&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Thu, 26 Aug 2004 08:39:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/capturing-awk-quot-system-quot-command-to-awk-variable/m-p/3365785#M97070</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2004-08-26T08:39:48Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing awk "system" command to awk variable?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/capturing-awk-quot-system-quot-command-to-awk-variable/m-p/3365786#M97071</link>
      <description>Spot on, cheers!</description>
      <pubDate>Thu, 26 Aug 2004 08:55:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/capturing-awk-quot-system-quot-command-to-awk-variable/m-p/3365786#M97071</guid>
      <dc:creator>Simon Hargrave</dc:creator>
      <dc:date>2004-08-26T08:55:35Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing awk "system" command to awk variable?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/capturing-awk-quot-system-quot-command-to-awk-variable/m-p/3365787#M97072</link>
      <description>man awk....&lt;BR /&gt;&lt;BR /&gt;"Finally, cmd | getline pipes the output of cmd into getline; each call of getline returns the next line of output from cmd."&lt;BR /&gt;&lt;BR /&gt;Example:&lt;BR /&gt;&lt;BR /&gt;awk 'BEGIN{while ("ps" | getline){ print "test " $1 " test"}}' /dev/null | more&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;This is similar to the following hack:&lt;BR /&gt;&lt;BR /&gt;mknod x&lt;BR /&gt;awk 'BEGIN{system("ps &amp;gt;&amp;gt; x&amp;amp;"); while (getline &amp;lt; "x"){ print "test " $1 " test"}}' /dev/null&lt;BR /&gt;rm x&lt;BR /&gt;&lt;BR /&gt;The are (gawk) extensions (Tru64) that have more support in this area. Like a native "&amp;amp;",&lt;BR /&gt;and close(file[, how]) to close files, pipes, or (two-way) pipse to co-processes.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Enjoy,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Thu, 26 Aug 2004 09:00:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/capturing-awk-quot-system-quot-command-to-awk-variable/m-p/3365787#M97072</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-08-26T09:00:33Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing awk "system" command to awk variable?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/capturing-awk-quot-system-quot-command-to-awk-variable/m-p/3365788#M97073</link>
      <description>The solutions above soes not give you&lt;BR /&gt;answers to the question how to get&lt;BR /&gt;systemoutput into a variable(!).&lt;BR /&gt;So here is the answer:&lt;BR /&gt;DO NOT USE system(), but escape back&lt;BR /&gt;to the shell:&lt;BR /&gt;&lt;BR /&gt;awk '{ ...&lt;BR /&gt;     x="'"`date`"'"&lt;BR /&gt;     printf "%s\n",x&lt;BR /&gt;    }'&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Ceesjan</description>
      <pubDate>Thu, 26 Aug 2004 09:26:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/capturing-awk-quot-system-quot-command-to-awk-variable/m-p/3365788#M97073</guid>
      <dc:creator>Ceesjan van Hattum</dc:creator>
      <dc:date>2004-08-26T09:26:18Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing awk "system" command to awk variable?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/capturing-awk-quot-system-quot-command-to-awk-variable/m-p/3365789#M97074</link>
      <description>Hi Ceesjan,&lt;BR /&gt;&lt;BR /&gt;How a dynamic string can be pushed in the command e.g. du &lt;FOLDER name=""&gt; -s ...&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Kuntal&lt;/FOLDER&gt;</description>
      <pubDate>Tue, 26 Dec 2006 21:39:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/capturing-awk-quot-system-quot-command-to-awk-variable/m-p/3365789#M97074</guid>
      <dc:creator>Kuntal Roy</dc:creator>
      <dc:date>2006-12-26T21:39:08Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing awk "system" command to awk variable?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/capturing-awk-quot-system-quot-command-to-awk-variable/m-p/3365790#M97075</link>
      <description>Hi Kuntal:&lt;BR /&gt;&lt;BR /&gt;Welcome to the Forums!  You should really not resurrect old threads, but rather post your own queries.  That said, however, you asked:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; How a dynamic string can be pushed in the command e.g. du &lt;FOLDER name=""&gt; -s ...&lt;BR /&gt;&lt;BR /&gt;# awk -v DIR="/tmp" 'END{while ("du -s " DIR|getline) {print}}' /dev/null&lt;BR /&gt;&lt;BR /&gt;Note that there is a space (blank) character after the '-s' flag and before the variable passed from the shell to 'awk' --- DIR.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;&lt;/FOLDER&gt;</description>
      <pubDate>Tue, 26 Dec 2006 22:21:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/capturing-awk-quot-system-quot-command-to-awk-variable/m-p/3365790#M97075</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-12-26T22:21:45Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing awk "system" command to awk variable?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/capturing-awk-quot-system-quot-command-to-awk-variable/m-p/3365791#M97076</link>
      <description>&lt;BR /&gt;Thanks for the respose. I think, my question was not clear enough.&lt;BR /&gt;&lt;BR /&gt;I have scenario such that instead of putting some static command 'date', I need to pass some dynamic string as a command - du &lt;NAME&gt; -s | awk '{print $1}'. I am already inside an awk command.&lt;BR /&gt;&lt;BR /&gt;awk '{ ...&lt;BR /&gt;x="'"`date`"'"&lt;BR /&gt;printf "%s\n",x&lt;BR /&gt;}'&lt;BR /&gt;&lt;BR /&gt;&lt;/NAME&gt;</description>
      <pubDate>Wed, 27 Dec 2006 11:00:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/capturing-awk-quot-system-quot-command-to-awk-variable/m-p/3365791#M97076</guid>
      <dc:creator>Kuntal Roy</dc:creator>
      <dc:date>2006-12-27T11:00:31Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing awk "system" command to awk variable?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/capturing-awk-quot-system-quot-command-to-awk-variable/m-p/3365792#M97077</link>
      <description>&amp;gt;Kuntal: I have scenario such that instead of putting some static command 'date',&lt;BR /&gt;&lt;BR /&gt;Can you evaluate the command before you invoke awk?  If not, you could invoke awk, execute the command and then go back in awk.</description>
      <pubDate>Thu, 04 Jan 2007 01:49:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/capturing-awk-quot-system-quot-command-to-awk-variable/m-p/3365792#M97077</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-01-04T01:49:37Z</dc:date>
    </item>
  </channel>
</rss>

