<?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 script help in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/awk-script-help/m-p/3586683#M103871</link>
    <description>Not enough ='s signs.  You're assing "ABC" to $2 etc. etc.&lt;BR /&gt;&lt;BR /&gt;if ($2 == "ABC") { print $1 }&lt;BR /&gt;else if ($2 == "BCD") { print $3 }&lt;BR /&gt;&lt;BR /&gt;etc. etc.&lt;BR /&gt;&lt;BR /&gt;NOTE: I highly recomend you use 'else if'.. saves a fair bit of processing, especially if you have a number of possibilities, unless you throw a 'next' in there somewhere.&lt;BR /&gt;</description>
    <pubDate>Wed, 20 Jul 2005 06:05:00 GMT</pubDate>
    <dc:creator>Stuart Browne</dc:creator>
    <dc:date>2005-07-20T06:05:00Z</dc:date>
    <item>
      <title>Awk script help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-script-help/m-p/3586682#M103870</link>
      <description>I am trying to write an awk script with multiple conditional statements and have some syntax wrong somewhere.  My record has 3 columns of data.  I want to print some stuff based on the second column's contents.  So code is something like:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;{&lt;BR /&gt;if ($2="ABC")&lt;BR /&gt;{printf $1}&lt;BR /&gt;if ($2="BCD")&lt;BR /&gt;{printf $3}   &lt;BR /&gt;}           etc.....&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;This code is executing every print statement nomatter what column 2 has in it.  &lt;BR /&gt;&lt;BR /&gt;What am i missing?&lt;BR /&gt;</description>
      <pubDate>Wed, 20 Jul 2005 05:56:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-script-help/m-p/3586682#M103870</guid>
      <dc:creator>Shannon_1</dc:creator>
      <dc:date>2005-07-20T05:56:23Z</dc:date>
    </item>
    <item>
      <title>Re: Awk script help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-script-help/m-p/3586683#M103871</link>
      <description>Not enough ='s signs.  You're assing "ABC" to $2 etc. etc.&lt;BR /&gt;&lt;BR /&gt;if ($2 == "ABC") { print $1 }&lt;BR /&gt;else if ($2 == "BCD") { print $3 }&lt;BR /&gt;&lt;BR /&gt;etc. etc.&lt;BR /&gt;&lt;BR /&gt;NOTE: I highly recomend you use 'else if'.. saves a fair bit of processing, especially if you have a number of possibilities, unless you throw a 'next' in there somewhere.&lt;BR /&gt;</description>
      <pubDate>Wed, 20 Jul 2005 06:05:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-script-help/m-p/3586683#M103871</guid>
      <dc:creator>Stuart Browne</dc:creator>
      <dc:date>2005-07-20T06:05:00Z</dc:date>
    </item>
    <item>
      <title>Re: Awk script help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-script-help/m-p/3586684#M103872</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;it should be == not =.&lt;BR /&gt;&lt;BR /&gt;Have you tried without if ?&lt;BR /&gt;&lt;BR /&gt;$2=="ABC" {printf $1}&lt;BR /&gt;$2=="BCD" {printf $3} &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 20 Jul 2005 06:10:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-script-help/m-p/3586684#M103872</guid>
      <dc:creator>Leif Halvarsson_2</dc:creator>
      <dc:date>2005-07-20T06:10:22Z</dc:date>
    </item>
    <item>
      <title>Re: Awk script help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-script-help/m-p/3586685#M103873</link>
      <description>Hi you can try the follwing is easy:&lt;BR /&gt;&lt;BR /&gt;awk ' $2 ~ /ABC/ {print $1}   $2 ~ /BCD/ {print $3}' filename&lt;BR /&gt;&lt;BR /&gt;I hope it helps.&lt;BR /&gt;&lt;BR /&gt;Juan</description>
      <pubDate>Wed, 20 Jul 2005 06:41:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-script-help/m-p/3586685#M103873</guid>
      <dc:creator>Juan M Leon</dc:creator>
      <dc:date>2005-07-20T06:41:37Z</dc:date>
    </item>
    <item>
      <title>Re: Awk script help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-script-help/m-p/3586686#M103874</link>
      <description>Why be AWKward?&lt;BR /&gt;As you have discovered, awk syntax is a pig.&lt;BR /&gt;In scripts, I get around it by using functions. This means more typing, but is much easier to code (and read)&lt;BR /&gt;e.g.&lt;BR /&gt;Say the line you want to extract fields from is in a variable called "myline"...&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;myfunc()&lt;BR /&gt;{&lt;BR /&gt;if [[ $2 = "ABC" ]] ; then&lt;BR /&gt;   echo $1&lt;BR /&gt;elif [[ $2 = "DEF" ]] ; then&lt;BR /&gt;   echo $3&lt;BR /&gt;# etc...&lt;BR /&gt;fi&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;#Main code&lt;BR /&gt;myline="ABC DEF GHI JKL MNO PQR STU VWX YZ"&lt;BR /&gt;myfunc $myline&lt;BR /&gt;&lt;BR /&gt;The above will echo GHI to the screen.</description>
      <pubDate>Mon, 01 Aug 2005 07:59:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-script-help/m-p/3586686#M103874</guid>
      <dc:creator>Gordon  Morrison</dc:creator>
      <dc:date>2005-08-01T07:59:04Z</dc:date>
    </item>
  </channel>
</rss>

