<?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 help in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3230005#M894367</link>
    <description>how would you optimize it?&lt;BR /&gt;</description>
    <pubDate>Thu, 25 Mar 2004 12:58:08 GMT</pubDate>
    <dc:creator>cbres00</dc:creator>
    <dc:date>2004-03-25T12:58:08Z</dc:date>
    <item>
      <title>Awk help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3229995#M894357</link>
      <description>I need to redirect awk output depending on how many pipes I find in a file.  Logic would go like this:&lt;BR /&gt;&lt;BR /&gt; awk  'BEGIN { FS="|"; OFS="|" }&lt;BR /&gt;  { (if NF = 4 )&lt;BR /&gt;    { print $0 } &amp;gt; good_file.txt&lt;BR /&gt;  else&lt;BR /&gt;     { print $0 } &amp;gt; bad_file.txt&lt;BR /&gt;  } &amp;lt; input_file.txt&lt;BR /&gt;&lt;BR /&gt;I keep getting the cryptic awk "something wrong on line 3" message.  What am I missing here?&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;CB&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 25 Mar 2004 11:59:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3229995#M894357</guid>
      <dc:creator>cbres00</dc:creator>
      <dc:date>2004-03-25T11:59:11Z</dc:date>
    </item>
    <item>
      <title>Re: Awk help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3229996#M894358</link>
      <description>The first thing that jumps out at me is&lt;BR /&gt;if (NF = 4)&lt;BR /&gt;I assume you meant a comparison rather than an assignment. Use "==".</description>
      <pubDate>Thu, 25 Mar 2004 12:05:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3229996#M894358</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-03-25T12:05:11Z</dc:date>
    </item>
    <item>
      <title>Re: Awk help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3229997#M894359</link>
      <description>Yes.  I still get an error msg on line 3, however.</description>
      <pubDate>Thu, 25 Mar 2004 12:10:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3229997#M894359</guid>
      <dc:creator>cbres00</dc:creator>
      <dc:date>2004-03-25T12:10:04Z</dc:date>
    </item>
    <item>
      <title>Re: Awk help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3229998#M894360</link>
      <description>Okay, I see a beginning single-quote but no terminal single-quote.&lt;BR /&gt;</description>
      <pubDate>Thu, 25 Mar 2004 12:15:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3229998#M894360</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-03-25T12:15:41Z</dc:date>
    </item>
    <item>
      <title>Re: Awk help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3229999#M894361</link>
      <description>Sorry....i have that in there, too.  ;-)&lt;BR /&gt;&lt;BR /&gt;Is my syntax correct for the 'if' statement?&lt;BR /&gt;I've tried restructuring this several ways but still no success.  Obviously I haven't hit the right way.  &lt;BR /&gt;&lt;BR /&gt;CB</description>
      <pubDate>Thu, 25 Mar 2004 12:20:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3229999#M894361</guid>
      <dc:creator>cbres00</dc:creator>
      <dc:date>2004-03-25T12:20:32Z</dc:date>
    </item>
    <item>
      <title>Re: Awk help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3230000#M894362</link>
      <description>man awk...&lt;BR /&gt; print [expression-list] [ &amp;gt; expression]&lt;BR /&gt;&lt;BR /&gt;So you need to (double)quote file.txt to make it an expression. And you have the closing curly brace in the wrong place.&lt;BR /&gt;Try something like:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;awk '{ if (NF==2) {print $0 &amp;gt;&amp;gt; "good_file.txt"} else {print $0 &amp;gt;&amp;gt; "bad_file.txt"}}'&lt;BR /&gt;aap&lt;BR /&gt;aap noot&lt;BR /&gt;aap noot mies&lt;BR /&gt;$ cat good_file.txt&lt;BR /&gt;aap noot&lt;BR /&gt;$ cat bad_file.txt&lt;BR /&gt;aap&lt;BR /&gt;aap noot mies&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 25 Mar 2004 12:22:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3230000#M894362</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-03-25T12:22:05Z</dc:date>
    </item>
    <item>
      <title>Re: Awk help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3230001#M894363</link>
      <description>Okay, I see a beginning single-quote but no terminal single-quote.&lt;BR /&gt;&lt;BR /&gt;Next (if NF = 4) should be "if (NF == 4)".&lt;BR /&gt;No quotes around the filename:&lt;BR /&gt;&lt;BR /&gt;awk 'BEGIN { FS="|"; OFS="|" }&lt;BR /&gt;{ &lt;BR /&gt;if (NF == 4 ) print $0  &amp;gt; "good_file.txt"&lt;BR /&gt;else print $0  &amp;gt; "bad_file.txt"&lt;BR /&gt;}' &amp;lt; input_file.txt&lt;BR /&gt;&lt;BR /&gt;should be close.&lt;BR /&gt;</description>
      <pubDate>Thu, 25 Mar 2004 12:23:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3230001#M894363</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-03-25T12:23:47Z</dc:date>
    </item>
    <item>
      <title>Re: Awk help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3230002#M894364</link>
      <description>&lt;BR /&gt;# perl -aF\\\| -pe'select@F==4?STDOUT:STDERR' input_file.txt &amp;gt;good_file.txt 2&amp;gt;bad_file.txt&lt;BR /&gt;&lt;BR /&gt;or&lt;BR /&gt;&lt;BR /&gt;# perl -aF\\\| -ne'print{@F==4?STDOUT:STDERR}$_' input_file.txt &amp;gt;good_file.txt 2&amp;gt;bad_file.txt&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Thu, 25 Mar 2004 12:37:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3230002#M894364</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2004-03-25T12:37:18Z</dc:date>
    </item>
    <item>
      <title>Re: Awk help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3230003#M894365</link>
      <description>Hmmmm....still not working.&lt;BR /&gt;I also need to replace the file name with a variable but I'm not sure it would matter.&lt;BR /&gt;&lt;BR /&gt;cb</description>
      <pubDate>Thu, 25 Mar 2004 12:39:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3230003#M894365</guid>
      <dc:creator>cbres00</dc:creator>
      <dc:date>2004-03-25T12:39:26Z</dc:date>
    </item>
    <item>
      <title>Re: Awk help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3230004#M894366</link>
      <description>Well, I just cut and pasted my last example and it worked. I won't suggest that your method are optimal but there should be no syntax errors.&lt;BR /&gt;</description>
      <pubDate>Thu, 25 Mar 2004 12:44:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3230004#M894366</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-03-25T12:44:09Z</dc:date>
    </item>
    <item>
      <title>Re: Awk help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3230005#M894367</link>
      <description>how would you optimize it?&lt;BR /&gt;</description>
      <pubDate>Thu, 25 Mar 2004 12:58:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3230005#M894367</guid>
      <dc:creator>cbres00</dc:creator>
      <dc:date>2004-03-25T12:58:08Z</dc:date>
    </item>
    <item>
      <title>Re: Awk help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3230006#M894368</link>
      <description>The biggest change that I would make is passing in variables using multiple -vbadfile=bad_file.txt arguments to replace your hard-coded filenames. Awk is good at redirecting output. Surprisingly, 'print $0 &amp;gt; "filename"' is efficient because the file is not opened and closed each time the print executes -- at least until awk runs out of file descriptors. I always shudder when I see hard-coded names put in any script. Imagine the consequences of running two of your scripts simultaneously. You might find it better to let awk function as a filter so that the "good" output simply goes to stdout while the "bad" output goes to an error file, possibly stderr.</description>
      <pubDate>Thu, 25 Mar 2004 13:14:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3230006#M894368</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-03-25T13:14:23Z</dc:date>
    </item>
    <item>
      <title>Re: Awk help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3230007#M894369</link>
      <description>See my post about three above this one!&lt;BR /&gt;Yes, I DO use variables....I have to.&lt;BR /&gt;&lt;BR /&gt;;-)&lt;BR /&gt;&lt;BR /&gt;cb</description>
      <pubDate>Thu, 25 Mar 2004 13:18:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3230007#M894369</guid>
      <dc:creator>cbres00</dc:creator>
      <dc:date>2004-03-25T13:18:19Z</dc:date>
    </item>
    <item>
      <title>Re: Awk help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3230008#M894370</link>
      <description>Argggghhh....&lt;BR /&gt;I decided to use nawk so I can find out what's exactly wrong here.&lt;BR /&gt;&lt;BR /&gt; awk  'BEGIN { FS="|"; OFS="|" }&lt;BR /&gt;     { if ( NF = 12 )&lt;BR /&gt;        {  print $0 }  &amp;gt;  ${tmp_file3}&lt;BR /&gt;       else&lt;BR /&gt;        {  print $0 } &amp;gt; ${tmp_file4}&lt;BR /&gt;     }' &amp;lt; ${tmp_file2}&lt;BR /&gt;&lt;BR /&gt;I get this error:&lt;BR /&gt;nawk: syntax error at source line 3&lt;BR /&gt; context is&lt;BR /&gt;   {  print $0 }  &amp;gt;&amp;gt;&amp;gt;  &amp;gt; &amp;lt;&amp;lt;&amp;lt;   ${tmp_file3}&lt;BR /&gt;nawk: illegal statement at source line 3&lt;BR /&gt;nawk: syntax error at source line 4&lt;BR /&gt;&lt;BR /&gt;I also tried to put double quotes around the variable but that didn't work.&lt;BR /&gt;&lt;BR /&gt;CB&lt;BR /&gt;</description>
      <pubDate>Thu, 25 Mar 2004 14:16:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3230008#M894370</guid>
      <dc:creator>cbres00</dc:creator>
      <dc:date>2004-03-25T14:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: Awk help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3230009#M894371</link>
      <description>I believe that this:&lt;BR /&gt;{ print $0 } &amp;gt; ${tmp_file3}&lt;BR /&gt;else&lt;BR /&gt;{ print $0 } &amp;gt; ${tmp_file4}&lt;BR /&gt;&lt;BR /&gt;should read:&lt;BR /&gt;&lt;BR /&gt;{ print $0  &amp;gt; ${tmp_file3} }&lt;BR /&gt;else&lt;BR /&gt;{ print $0  &amp;gt; ${tmp_file4} }&lt;BR /&gt;&lt;BR /&gt;By including the "}" before the "&amp;gt;", you have effectively ended the print statement.&lt;BR /&gt;&lt;BR /&gt;Best regards,&lt;BR /&gt;&lt;BR /&gt;KEnt M. Ostby&lt;BR /&gt;</description>
      <pubDate>Thu, 25 Mar 2004 14:46:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3230009#M894371</guid>
      <dc:creator>Kent Ostby</dc:creator>
      <dc:date>2004-03-25T14:46:38Z</dc:date>
    </item>
    <item>
      <title>Re: Awk help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3230010#M894372</link>
      <description>Hi,&lt;BR /&gt;I do not have a system available at the moment, but I think your problems derive from the use of the dollar sign, e.g.:&lt;BR /&gt; print $0 } &amp;gt; ${tmp_file3}&lt;BR /&gt;You cannot directly expand a shell variable in an awk script by a dollar sign, awk will not interpret thia as a shell variable.&lt;BR /&gt;You have to define which shell variables you want to use in your awk script, e.g.&lt;BR /&gt;awk -v FILE1=/tmp/flip -v FILE2=/tmp/flop 'rest of script in which you use the variables in awk without the dollar sign, e.g. print &amp;gt;FLIP'&lt;BR /&gt; &lt;BR /&gt;regards,&lt;BR /&gt;John K.&lt;BR /&gt;</description>
      <pubDate>Thu, 25 Mar 2004 15:09:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3230010#M894372</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2004-03-25T15:09:43Z</dc:date>
    </item>
    <item>
      <title>Re: Awk help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3230011#M894373</link>
      <description>You are indeed correct!! I had to put the ${tmp_file2} reference in double- then single-quotes (" ' ${tmp_file2} ' ").   It works like a charm.&lt;BR /&gt;&lt;BR /&gt;Thanks to all who helped me!&lt;BR /&gt;&lt;BR /&gt;Cathy</description>
      <pubDate>Thu, 25 Mar 2004 15:13:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-help/m-p/3230011#M894373</guid>
      <dc:creator>cbres00</dc:creator>
      <dc:date>2004-03-25T15:13:07Z</dc:date>
    </item>
  </channel>
</rss>

