<?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: Awk functionality in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-functionality/m-p/2533497#M869503</link>
    <description>Hi Dave,&lt;BR /&gt;&lt;BR /&gt;Your problem is not the single quote in awk but rather the single in the surrounding shell quote. On easy way around this is to build an awk script 'on the fly' using the 'here doc' convention. This also allows you to build up more than simple one-liners.&lt;BR /&gt;&lt;BR /&gt;The script build your awk file and writes it to a temp file, executes awk, and then removes the temp file. Being an old C programmer i also swapped your print to a printf - it's more powerful.&lt;BR /&gt;&lt;BR /&gt;Something like this:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;TDIR=${TMPDIR:-/var/tmp}&lt;BR /&gt;PID=${$}&lt;BR /&gt;A1=${TDIR}/X${PID}_1.awk&lt;BR /&gt;&lt;BR /&gt;cat &amp;lt;&amp;lt; !EOF! &amp;gt; $A1&lt;BR /&gt;{&lt;BR /&gt;  printf("Hi Dave ' %s\n",\$1)&lt;BR /&gt;}&lt;BR /&gt;!EOF!&lt;BR /&gt;&lt;BR /&gt;cat myfile | awk -f ${A1}&lt;BR /&gt;STAT=$?&lt;BR /&gt;rm -f $A1&lt;BR /&gt;exit $STAT&lt;BR /&gt;&lt;BR /&gt;If my typing is correct, that should do it. Note that within the 'here docs' section the '$' has to be escaped with '\'.&lt;BR /&gt;&lt;BR /&gt;Regards, Clay&lt;BR /&gt;</description>
    <pubDate>Mon, 28 May 2001 14:48:16 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2001-05-28T14:48:16Z</dc:date>
    <item>
      <title>Awk functionality</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-functionality/m-p/2533496#M869502</link>
      <description>Hi.&lt;BR /&gt;&lt;BR /&gt;I am trying to build a line from a file using awk and I am having a problem with inserting ' into the line as the ' charatcter is used to delimit the awk function.   For example&lt;BR /&gt;&lt;BR /&gt;cat file|awk '{print "hi dave \'" $1}'&lt;BR /&gt;su: Syntax error: `"' is not matched.&lt;BR /&gt;&lt;BR /&gt;my output should be &lt;BR /&gt;hi dave ' walley&lt;BR /&gt;&lt;BR /&gt;Can anybody tell me how to include the single quote in the output.&lt;BR /&gt;&lt;BR /&gt;Thanking you &lt;BR /&gt;&lt;BR /&gt;Dave</description>
      <pubDate>Mon, 28 May 2001 14:20:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-functionality/m-p/2533496#M869502</guid>
      <dc:creator>Dave Walley</dc:creator>
      <dc:date>2001-05-28T14:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: Awk functionality</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-functionality/m-p/2533497#M869503</link>
      <description>Hi Dave,&lt;BR /&gt;&lt;BR /&gt;Your problem is not the single quote in awk but rather the single in the surrounding shell quote. On easy way around this is to build an awk script 'on the fly' using the 'here doc' convention. This also allows you to build up more than simple one-liners.&lt;BR /&gt;&lt;BR /&gt;The script build your awk file and writes it to a temp file, executes awk, and then removes the temp file. Being an old C programmer i also swapped your print to a printf - it's more powerful.&lt;BR /&gt;&lt;BR /&gt;Something like this:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;TDIR=${TMPDIR:-/var/tmp}&lt;BR /&gt;PID=${$}&lt;BR /&gt;A1=${TDIR}/X${PID}_1.awk&lt;BR /&gt;&lt;BR /&gt;cat &amp;lt;&amp;lt; !EOF! &amp;gt; $A1&lt;BR /&gt;{&lt;BR /&gt;  printf("Hi Dave ' %s\n",\$1)&lt;BR /&gt;}&lt;BR /&gt;!EOF!&lt;BR /&gt;&lt;BR /&gt;cat myfile | awk -f ${A1}&lt;BR /&gt;STAT=$?&lt;BR /&gt;rm -f $A1&lt;BR /&gt;exit $STAT&lt;BR /&gt;&lt;BR /&gt;If my typing is correct, that should do it. Note that within the 'here docs' section the '$' has to be escaped with '\'.&lt;BR /&gt;&lt;BR /&gt;Regards, Clay&lt;BR /&gt;</description>
      <pubDate>Mon, 28 May 2001 14:48:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-functionality/m-p/2533497#M869503</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2001-05-28T14:48:16Z</dc:date>
    </item>
    <item>
      <title>Re: Awk functionality</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-functionality/m-p/2533498#M869504</link>
      <description>Clay.&lt;BR /&gt;&lt;BR /&gt;I have tried your suggestion and received absolutely nothing.&lt;BR /&gt;&lt;BR /&gt;By running the myfile line I get&lt;BR /&gt;&lt;BR /&gt; syntax error The source line is 5.&lt;BR /&gt; The error context is&lt;BR /&gt;                !EOF!  &amp;gt;&amp;gt;&amp;gt; &lt;BR /&gt; &amp;lt;&amp;lt;&amp;lt; &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;dave</description>
      <pubDate>Mon, 28 May 2001 15:09:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-functionality/m-p/2533498#M869504</guid>
      <dc:creator>Dave Walley</dc:creator>
      <dc:date>2001-05-28T15:09:34Z</dc:date>
    </item>
    <item>
      <title>Re: Awk functionality</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-functionality/m-p/2533499#M869505</link>
      <description>Or you could type your command like this :&lt;BR /&gt;&lt;BR /&gt;cat file | awk '{print "hi dave '\''" $1}'&lt;BR /&gt;&lt;BR /&gt;close the quote,&lt;BR /&gt;insert an escaped quote,&lt;BR /&gt;reopen the quote&lt;BR /&gt;</description>
      <pubDate>Mon, 28 May 2001 15:13:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-functionality/m-p/2533499#M869505</guid>
      <dc:creator>Laurent Paumier</dc:creator>
      <dc:date>2001-05-28T15:13:16Z</dc:date>
    </item>
    <item>
      <title>Re: Awk functionality</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-functionality/m-p/2533500#M869506</link>
      <description>Hi Dave,&lt;BR /&gt;&lt;BR /&gt;My typing was ok but apparently the browser doesn't do a perfect job of copy/paste. When I copied in my own example, it didn't work. The problem was extra whitespace after !EOF! at the end of the here docs section. Remove the extra spaces at the end of the line and all should be well. And again, I deliberately made this more complex than a one-liner in case your script gets more complicated.&lt;BR /&gt;&lt;BR /&gt;Regards, Clay&lt;BR /&gt;</description>
      <pubDate>Mon, 28 May 2001 15:33:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-functionality/m-p/2533500#M869506</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2001-05-28T15:33:32Z</dc:date>
    </item>
  </channel>
</rss>

