<?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 help !! in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/2884344#M3402</link>
    <description>Hi there,&lt;BR /&gt;i'm going crazy in creating a small script in awk.&lt;BR /&gt;What i want to do is if in a field i have M replace value with 1 else with 0.&lt;BR /&gt;This is my script&lt;BR /&gt;BEGIN { FS="|" ; OFS="|"}&lt;BR /&gt;  { if ($29=="M") { $29=1 }&lt;BR /&gt;    [ else $29=0 ]&lt;BR /&gt;    print $0&lt;BR /&gt;  }&lt;BR /&gt;I get error when i issue:&lt;BR /&gt;cat file | awk -f script.awk | moreSyntax Error The source line is 3.&lt;BR /&gt; The error context is&lt;BR /&gt;                    &amp;gt;&amp;gt;&amp;gt;  [ &amp;lt;&amp;lt;&amp;lt;&lt;BR /&gt; awk: 0602-502 The statement cannot be correctly parsed. The source line is 3.&lt;BR /&gt;&lt;BR /&gt;but in the man there's written:if ( Expression ) { Statement } [ else Action ]&lt;BR /&gt;so what's wrong?&lt;BR /&gt;any help is appreciated.&lt;BR /&gt;Thanks&lt;BR /&gt;tarek&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Fri, 17 Jan 2003 10:28:33 GMT</pubDate>
    <dc:creator>Tarek_1</dc:creator>
    <dc:date>2003-01-17T10:28:33Z</dc:date>
    <item>
      <title>awk help !!</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/2884344#M3402</link>
      <description>Hi there,&lt;BR /&gt;i'm going crazy in creating a small script in awk.&lt;BR /&gt;What i want to do is if in a field i have M replace value with 1 else with 0.&lt;BR /&gt;This is my script&lt;BR /&gt;BEGIN { FS="|" ; OFS="|"}&lt;BR /&gt;  { if ($29=="M") { $29=1 }&lt;BR /&gt;    [ else $29=0 ]&lt;BR /&gt;    print $0&lt;BR /&gt;  }&lt;BR /&gt;I get error when i issue:&lt;BR /&gt;cat file | awk -f script.awk | moreSyntax Error The source line is 3.&lt;BR /&gt; The error context is&lt;BR /&gt;                    &amp;gt;&amp;gt;&amp;gt;  [ &amp;lt;&amp;lt;&amp;lt;&lt;BR /&gt; awk: 0602-502 The statement cannot be correctly parsed. The source line is 3.&lt;BR /&gt;&lt;BR /&gt;but in the man there's written:if ( Expression ) { Statement } [ else Action ]&lt;BR /&gt;so what's wrong?&lt;BR /&gt;any help is appreciated.&lt;BR /&gt;Thanks&lt;BR /&gt;tarek&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 17 Jan 2003 10:28:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/2884344#M3402</guid>
      <dc:creator>Tarek_1</dc:creator>
      <dc:date>2003-01-17T10:28:33Z</dc:date>
    </item>
    <item>
      <title>Re: awk help !!</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/2884345#M3403</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I think you might be able to do it like this:&lt;BR /&gt;&lt;BR /&gt;{$29=($29 == "M") ? "1" : "0"&lt;BR /&gt;print $0&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;This sets the value of $29 according to the test of $29 equal to "M".  If the test is true, $29 is set to "1" else it is set to "0".&lt;BR /&gt;&lt;BR /&gt;Here is a one line example where I change the password field in /etc/passwd to an "X" if the second field isn't equal to an "*", otherwise it is set to "*":&lt;BR /&gt;&lt;BR /&gt;awk -F: '{$2=($2 == "*") ? $2 : "X"; print $0}' /etc/passwd&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I hope that helps a bit.&lt;BR /&gt;&lt;BR /&gt;JP&lt;BR /&gt;</description>
      <pubDate>Fri, 17 Jan 2003 15:46:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/2884345#M3403</guid>
      <dc:creator>John Poff</dc:creator>
      <dc:date>2003-01-17T15:46:59Z</dc:date>
    </item>
    <item>
      <title>Re: awk help !!</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/2884346#M3404</link>
      <description>John,&lt;BR /&gt;maybe you're script is write but i think with me it isn't functioning (no errors are given but the output is wrong) because i haven't specified the field separtor.&lt;BR /&gt;My file is like this:&lt;BR /&gt;aa|aa|ds|a;b;c;|sa|as|af&lt;BR /&gt;for me these are 7 fields because the separtor is | .&lt;BR /&gt;i have to specify it.&lt;BR /&gt;i issued this command:&lt;BR /&gt;awk -F: '{$29=($29 == "M") ? "1" : "2"; print $0}' filename&lt;BR /&gt;&lt;BR /&gt;How can i specify the FS?&lt;BR /&gt;However thanks very much for your precious help.&lt;BR /&gt;&lt;BR /&gt;Tarek&lt;BR /&gt;</description>
      <pubDate>Fri, 17 Jan 2003 16:23:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/2884346#M3404</guid>
      <dc:creator>Tarek_1</dc:creator>
      <dc:date>2003-01-17T16:23:55Z</dc:date>
    </item>
    <item>
      <title>Re: awk help !!</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/2884347#M3405</link>
      <description>Hi Tarek,&lt;BR /&gt;&lt;BR /&gt;The -F option specifies the field separator, so for your example try this:&lt;BR /&gt;&lt;BR /&gt;awk -F| '{$29=($29 == "M") ? "1" : "2"; print $0}' filename &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;JP&lt;BR /&gt;</description>
      <pubDate>Fri, 17 Jan 2003 16:35:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/2884347#M3405</guid>
      <dc:creator>John Poff</dc:creator>
      <dc:date>2003-01-17T16:35:24Z</dc:date>
    </item>
    <item>
      <title>Re: awk help !!</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/2884348#M3406</link>
      <description>Again, not working:&lt;BR /&gt;awk -F| '{$29=($29 == "M") ? "1" : "2"; print $0}' filename&lt;BR /&gt;awk: A flag requires a parameter: F&lt;BR /&gt;Usage: awk [-F Character][-v Variable=Value][-f File|Commands][Variable=Value|File ...]&lt;BR /&gt;ksh: {$29=($29 == "M") ? "1" : "2"; print $0}:  not found.&lt;BR /&gt;&lt;BR /&gt;also tried with -F | , same stuff.&lt;BR /&gt;if i put -F "|" it works but not fine:&lt;BR /&gt;i get all $29=2 and in the output file the field separator is space instead of |</description>
      <pubDate>Fri, 17 Jan 2003 16:53:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/2884348#M3406</guid>
      <dc:creator>Tarek_1</dc:creator>
      <dc:date>2003-01-17T16:53:28Z</dc:date>
    </item>
    <item>
      <title>Re: awk help !!</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/2884349#M3407</link>
      <description>&lt;BR /&gt;Suspect you need a backslash before your | or some quotes otherwise the shell thinks you want to pipe the rest somewhere.  Try:&lt;BR /&gt;&lt;BR /&gt;awk -F \| '{$29=($29 == "M") ? "1" : "2"; print $0}' filename &lt;BR /&gt;&lt;BR /&gt;Also in your first post you misunderstood the use of the square brackets.  These are conventionally used in a programming description to indicate that the stuff in the brackets is optional.  They do not appear in real life.  I suspect the curly brackets were the same thing. &lt;BR /&gt;&lt;BR /&gt;Aren't we supposed to use gawk in Linux?&lt;BR /&gt;&lt;BR /&gt;Ron&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 17 Jan 2003 17:59:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/2884349#M3407</guid>
      <dc:creator>Ron Kinner</dc:creator>
      <dc:date>2003-01-17T17:59:20Z</dc:date>
    </item>
    <item>
      <title>Re: awk help !!</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/2884350#M3408</link>
      <description>Hi again,&lt;BR /&gt;&lt;BR /&gt;Ron is right.  I wasn't thinking about the vertical bar being the pipe symbol.  Escaping it should make your line work.  I tried it here and it seemed to work fine.&lt;BR /&gt;&lt;BR /&gt;Ron, On my RedHat 7.2 box the /bin/awk file is a symlink to gawk, so I guess I am using gawk.&lt;BR /&gt;&lt;BR /&gt;JP&lt;BR /&gt;</description>
      <pubDate>Fri, 17 Jan 2003 18:52:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/2884350#M3408</guid>
      <dc:creator>John Poff</dc:creator>
      <dc:date>2003-01-17T18:52:05Z</dc:date>
    </item>
    <item>
      <title>Re: awk help !!</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/2884351#M3409</link>
      <description>I may be wrong, but in the man pages anything within [..] means optional.  If you are using that optional item the [ and ] are not included, you need to the line: &lt;BR /&gt;[ else $29=0 ]&lt;BR /&gt;&lt;BR /&gt;into&lt;BR /&gt;else { $29=0 }&lt;BR /&gt;&lt;BR /&gt;Cheers&lt;BR /&gt;Steven</description>
      <pubDate>Sun, 19 Jan 2003 20:03:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/2884351#M3409</guid>
      <dc:creator>Procnus</dc:creator>
      <dc:date>2003-01-19T20:03:09Z</dc:date>
    </item>
  </channel>
</rss>

