<?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 and else statements in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047866#M96130</link>
    <description>ok thanks all,&lt;BR /&gt;&lt;BR /&gt;looks like I forgot {} for the else statement.&lt;BR /&gt;&lt;BR /&gt;will add this to my never ending notes.&lt;BR /&gt;&lt;BR /&gt;Chris</description>
    <pubDate>Tue, 22 May 2007 03:20:27 GMT</pubDate>
    <dc:creator>lawrenzo_1</dc:creator>
    <dc:date>2007-05-22T03:20:27Z</dc:date>
    <item>
      <title>awk and else statements</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047854#M96118</link>
      <description>Hi all,&lt;BR /&gt;&lt;BR /&gt;I have created an awk statement that works well:&lt;BR /&gt;&lt;BR /&gt;for i in `etc etc`&lt;BR /&gt;do&lt;BR /&gt;&lt;COMMAND&gt; |awk '/Virtual I\/O Bus/ {line=line+1};END{if(line&amp;gt;1) print serv": virtual server"}'&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;however how can I use else in this statement - the following does not work:&lt;BR /&gt;&lt;BR /&gt;&lt;COMMAND&gt; |awk -v serv=$i '/Virtual I\/O Bus/ {line=line+1};END{if(line&amp;gt;1) print serv": virtual server";else print serv": not a virtual server"}'&lt;BR /&gt;&lt;BR /&gt;all servers in the list come back with &lt;BR /&gt;&lt;BR /&gt;serv: not a virtual server&lt;BR /&gt;&lt;BR /&gt;any help would be great&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;Chris&lt;/COMMAND&gt;&lt;/COMMAND&gt;</description>
      <pubDate>Fri, 18 May 2007 10:55:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047854#M96118</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2007-05-18T10:55:34Z</dc:date>
    </item>
    <item>
      <title>Re: awk and else statements</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047855#M96119</link>
      <description>Hi Chris:&lt;BR /&gt;&lt;BR /&gt;&lt;COMMAND&gt; |awk -v serv=$i '/Virtual I\/O Bus/ {line=line+1};END{if(line&amp;gt;1) {print serv": virtual server"} else {print serv": not a virtual server"}}'&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;/COMMAND&gt;</description>
      <pubDate>Fri, 18 May 2007 11:08:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047855#M96119</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-05-18T11:08:19Z</dc:date>
    </item>
    <item>
      <title>Re: awk and else statements</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047856#M96120</link>
      <description>First, you don't need your line variable because awk has the built-in NR variable.&lt;BR /&gt;&lt;BR /&gt;Now try this:&lt;BR /&gt;ls | awk 'END { if (NR &amp;gt; 1) {print "More"} else {print "Less than two"} }'&lt;BR /&gt;&lt;BR /&gt;echo "One thing" | awk 'END { if (NR &amp;gt; 1) {print "More"} else {print "Less than two"} }'&lt;BR /&gt;&lt;BR /&gt;I'm just using ls and echo to supply more than one line and one line respectively.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 18 May 2007 11:17:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047856#M96120</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2007-05-18T11:17:21Z</dc:date>
    </item>
    <item>
      <title>Re: awk and else statements</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047857#M96121</link>
      <description>Hi Chris,&lt;BR /&gt;&lt;BR /&gt;Both cases of your if-else statement work properly--unaltered--on my system.  Make sure you have specified the correct search pattern and look out for any unexpected input.&lt;BR /&gt;&lt;BR /&gt;PCS</description>
      <pubDate>Fri, 18 May 2007 11:20:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047857#M96121</guid>
      <dc:creator>spex</dc:creator>
      <dc:date>2007-05-18T11:20:27Z</dc:date>
    </item>
    <item>
      <title>Re: awk and else statements</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047858#M96122</link>
      <description>&lt;!--!*#--&gt;Either try parenthesizing the if else or Most likely it is the semi-colon before the END that maybe causing erroneous results so try removing it and see if that fixes it or convert it into a multi-line awk construct:&lt;BR /&gt;&lt;BR /&gt;awk -v serv=$i '/Virtual I\/O Bus/ {line=line+1}END{if(line&amp;gt;1){print serv": virtual server"}else print serv": not a virtual server"}'&lt;BR /&gt;&lt;BR /&gt;...or...&lt;BR /&gt;&lt;BR /&gt;awk -v serv=$i '/Virtual I\/O Bus/ {line=line+1}&lt;BR /&gt;END {if(line&amp;gt;1)&lt;BR /&gt;       print serv": virtual server";else print serv": not a virtual server"}'</description>
      <pubDate>Fri, 18 May 2007 11:54:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047858#M96122</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-05-18T11:54:53Z</dc:date>
    </item>
    <item>
      <title>Re: awk and else statements</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047859#M96123</link>
      <description>&lt;!--!*#--&gt;I'm not sure whats wrong.  As SPEX says, it works for me if the input has multiple instances of that string.&lt;BR /&gt;&lt;BR /&gt;You may want to remove that ";: as JRF says?&lt;BR /&gt;&lt;BR /&gt;You may also want to use a better awk formating style and not use just one line:&lt;BR /&gt;$ &lt;COMMAND&gt; |awk -v serv=$i '&lt;BR /&gt;/Virtual I\/O Bus/ {line=line+1}&lt;BR /&gt;END {&lt;BR /&gt;if (line&amp;gt;1) {&lt;BR /&gt;   print serv": virtual server"&lt;BR /&gt;} else {&lt;BR /&gt;   print serv": not a virtual server"&lt;BR /&gt;}&lt;BR /&gt;}'&lt;BR /&gt;&lt;BR /&gt;&amp;gt;Clay:  First, you don't need your line variable because awk has the built-in NR variable.&lt;BR /&gt;&lt;BR /&gt;Sure it does.  line is counting matches, not lines.  Of course if the name was called "matches", Clay would be happier.  ;-)&lt;/COMMAND&gt;</description>
      <pubDate>Sat, 19 May 2007 01:24:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047859#M96123</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-05-19T01:24:07Z</dc:date>
    </item>
    <item>
      <title>Re: awk and else statements</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047860#M96124</link>
      <description>You are correct; I missed the first single quote in the second example. I read all that -v serv=$i/Virtual ... stuff ass the variable actually being passed if so that the line count was unconditional.</description>
      <pubDate>Sat, 19 May 2007 09:43:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047860#M96124</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2007-05-19T09:43:27Z</dc:date>
    </item>
    <item>
      <title>Re: awk and else statements</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047861#M96125</link>
      <description>Like for the rest, it works for me.&lt;BR /&gt;&lt;BR /&gt;I guess the &lt;COMMAND&gt; is not delivering exactly what you expect.&lt;BR /&gt;&lt;BR /&gt;Hints... try something simpler&lt;BR /&gt;&lt;BR /&gt;&lt;COMMAND&gt; |awk '/Virtual/{line++; print line, $0}'&lt;BR /&gt;&lt;BR /&gt;next:&lt;BR /&gt;&lt;BR /&gt;&lt;COMMAND&gt; |awk -v serv=$i '/Virtual I\/O Bus/ {line=line+1};END{ print serv, line}'&lt;BR /&gt;&lt;BR /&gt;Those \escaped characters are always tricky.&lt;BR /&gt;If there is no risk for false positives, then just replace by a '.' for 'any' character. &lt;BR /&gt;&lt;BR /&gt;Consider this:&lt;BR /&gt;&lt;BR /&gt;$  awk -v serv=$i '/Virtual I.O Bus/{line++} END { not=(line&amp;lt;2)? ":not a" : ":"; print serv not "vi&lt;BR /&gt;rtual server"}'&lt;BR /&gt;&lt;BR /&gt;Here I conditionally modify a variable in the print line instead of conditionally selecting the 'right' print line.&lt;BR /&gt;Why? Because now the rest of the print statement will be exactly the same. Equally broken or equally correct. Easier to maintain!&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;/COMMAND&gt;&lt;/COMMAND&gt;&lt;/COMMAND&gt;</description>
      <pubDate>Sat, 19 May 2007 14:40:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047861#M96125</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-05-19T14:40:58Z</dc:date>
    </item>
    <item>
      <title>Re: awk and else statements</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047862#M96126</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Hein's remark is important!&lt;BR /&gt;&amp;gt;&amp;gt;&lt;BR /&gt;Those \escaped characters are always tricky.&lt;BR /&gt;If there is no risk for false positives, then just replace by a '.' for 'any' character.&lt;BR /&gt;&amp;lt;&amp;lt;&lt;BR /&gt;&lt;BR /&gt;But don't use '.' in that case but '[/]' like this:&lt;BR /&gt;awk '/Virtual I[/]O Bus/ {..&lt;BR /&gt;&lt;BR /&gt;This can always be used as a save 'esacpe' mechanism.&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
      <pubDate>Mon, 21 May 2007 11:16:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047862#M96126</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2007-05-21T11:16:40Z</dc:date>
    </item>
    <item>
      <title>Re: awk and else statements</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047863#M96127</link>
      <description>What should be the output of "&lt;COMMAND&gt;" if "serv is a virtual server" should it output any lines that have "Virtual I/O Bus" or not?&lt;BR /&gt;&lt;BR /&gt;~thanks&lt;/COMMAND&gt;</description>
      <pubDate>Mon, 21 May 2007 11:55:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047863#M96127</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-05-21T11:55:49Z</dc:date>
    </item>
    <item>
      <title>Re: awk and else statements</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047864#M96128</link>
      <description>&amp;gt;Sandman: What should be the output of "&lt;COMMAND&gt;" if "serv is a virtual server" should it output any lines that have "Virtual I/O Bus" or not?&lt;BR /&gt;&lt;BR /&gt;I assumed that it outputs more than one.  And with that assumption, my awk fragment worked.&lt;/COMMAND&gt;</description>
      <pubDate>Mon, 21 May 2007 12:39:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047864#M96128</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-05-21T12:39:59Z</dc:date>
    </item>
    <item>
      <title>Re: awk and else statements</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047865#M96129</link>
      <description>So does my awk script Dennis but I wanted to clarify whether the author of the thread had made a typo in... if(line&amp;gt;1) ...where the intention was... if(line&amp;gt;0).&lt;BR /&gt;&lt;BR /&gt;~cheers</description>
      <pubDate>Mon, 21 May 2007 14:23:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047865#M96129</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-05-21T14:23:32Z</dc:date>
    </item>
    <item>
      <title>Re: awk and else statements</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047866#M96130</link>
      <description>ok thanks all,&lt;BR /&gt;&lt;BR /&gt;looks like I forgot {} for the else statement.&lt;BR /&gt;&lt;BR /&gt;will add this to my never ending notes.&lt;BR /&gt;&lt;BR /&gt;Chris</description>
      <pubDate>Tue, 22 May 2007 03:20:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047866#M96130</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2007-05-22T03:20:27Z</dc:date>
    </item>
    <item>
      <title>Re: awk and else statements</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047867#M96131</link>
      <description>Thanks again all,&lt;BR /&gt;&lt;BR /&gt;sandman you are correct line should be &amp;gt;0 and not &amp;gt;1.&lt;BR /&gt;&lt;BR /&gt;all examples will help in the future.&lt;BR /&gt;&lt;BR /&gt;Cheers &lt;BR /&gt;&lt;BR /&gt;Chris.</description>
      <pubDate>Tue, 22 May 2007 03:28:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047867#M96131</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2007-05-22T03:28:16Z</dc:date>
    </item>
    <item>
      <title>Re: awk and else statements</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047868#M96132</link>
      <description>&lt;!--!*#--&gt;&amp;gt;line should be &amp;gt;0 and not &amp;gt;1.&lt;BR /&gt;&lt;BR /&gt;If this is the case, there is no need to count them up.  Just do:&lt;BR /&gt;/Virtual I\/O Bus/ { print serv ": virtual server"; exit}&lt;BR /&gt;END { print serv ": not a virtual server"} &lt;BR /&gt;&lt;BR /&gt;You can also make it simpler by just using grep:&lt;BR /&gt;&lt;COMMAND&gt; | grep -q "Virtual I/O Bus"&lt;BR /&gt;if [ $? -eq 0 ]; then&lt;BR /&gt;   echo "$i: virtual server"&lt;BR /&gt;else&lt;BR /&gt;   echo "$i: not a virtual server"&lt;BR /&gt;fi&lt;/COMMAND&gt;</description>
      <pubDate>Tue, 22 May 2007 03:48:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047868#M96132</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-05-22T03:48:31Z</dc:date>
    </item>
    <item>
      <title>Re: awk and else statements</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047869#M96133</link>
      <description>Thanks Dennis,&lt;BR /&gt;&lt;BR /&gt;I am pretty handy with shell scripting so I am attempting to learn awk / sed and later on perl ....&lt;BR /&gt;&lt;BR /&gt;but thanks for the examples.&lt;BR /&gt;&lt;BR /&gt;Chris</description>
      <pubDate>Tue, 22 May 2007 03:51:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-and-else-statements/m-p/5047869#M96133</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2007-05-22T03:51:21Z</dc:date>
    </item>
  </channel>
</rss>

