<?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 getline help in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/awk-getline-help/m-p/4091314#M92272</link>
    <description>Yes, that's a fine solution IF the problem is to create a simple array with all the line from that file.&lt;BR /&gt;&lt;BR /&gt;But that's so boring!&lt;BR /&gt;&lt;BR /&gt;What are you going to do with the data from that array later? Run it through a loop 'looking' for stuff?&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt; Hein, I am using the same code for a different purpose - I could use grep etc but still attempting to improve my awk skills.&lt;BR /&gt;&lt;BR /&gt;Exactly! That's precisely why I hinted you towards picking a useful key for the array, not just a list of numbers 1..end.&lt;BR /&gt;With a good key/index you can do a direct lookup suing the 'i in array' construct. You can also readily 'delete' specif array elements which are (no longer) useful.&lt;BR /&gt;&lt;BR /&gt;Check it out. It's useful and will bring you to a whole new level in awk usage, getting you ready for... perl&lt;BR /&gt;&lt;BR /&gt;:-)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Wed, 24 Oct 2007 07:39:43 GMT</pubDate>
    <dc:creator>Hein van den Heuvel</dc:creator>
    <dc:date>2007-10-24T07:39:43Z</dc:date>
    <item>
      <title>AWK getline help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-getline-help/m-p/4091306#M92264</link>
      <description>Hello all,&lt;BR /&gt;&lt;BR /&gt;I am using awk to filter a file, below is syntax that has been given to me in a previous thread however I cannot seem to get it to work:&lt;BR /&gt;&lt;BR /&gt;awk 'BEGIN{while (getline LINE &amp;lt; "allservers.csv" &amp;gt; 0) {a[++$i]=LINE}}' serverlistfinal.txt&lt;BR /&gt;&lt;BR /&gt;error message is:&lt;BR /&gt;awk: Field $() is not correct.&lt;BR /&gt;&lt;BR /&gt;any help is greatly appreciated.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 24 Oct 2007 06:20:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-getline-help/m-p/4091306#M92264</guid>
      <dc:creator>lawrenzo</dc:creator>
      <dc:date>2007-10-24T06:20:50Z</dc:date>
    </item>
    <item>
      <title>Re: AWK getline help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-getline-help/m-p/4091307#M92265</link>
      <description>This is a snippet from a larger program right?&lt;BR /&gt;&lt;BR /&gt;So what is the "$i" supposed to do?&lt;BR /&gt;&lt;BR /&gt;I suspect you just want 'i', no $&lt;BR /&gt;&lt;BR /&gt;In PERL the variablea are $i and such&lt;BR /&gt;&lt;BR /&gt;in AWK the $x referer to auto-split fields sucht as $1 for the first, $2 for teh second, $NF for the last, from the last line processed in $0.&lt;BR /&gt;&lt;BR /&gt;hth,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Wed, 24 Oct 2007 06:42:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-getline-help/m-p/4091307#M92265</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-10-24T06:42:45Z</dc:date>
    </item>
    <item>
      <title>Re: AWK getline help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-getline-help/m-p/4091308#M92266</link>
      <description>Hi Chris:&lt;BR /&gt;&lt;BR /&gt;# awk 'BEGIN{while ((getline LINE &amp;lt; "/etc/hosts") &amp;gt; 0) {a[++i]=LINE}}' serverlistfinal.txt&lt;BR /&gt;&lt;BR /&gt;...as for example:&lt;BR /&gt;&lt;BR /&gt;# awk 'BEGIN{while ((getline LINE &amp;lt; "/etc/hosts") &amp;gt; 0) {a[++i]=LINE}};END{for (i=1;i&amp;lt;10;i++) {print a[i]}}' /dev/null&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 24 Oct 2007 06:47:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-getline-help/m-p/4091308#M92266</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-10-24T06:47:47Z</dc:date>
    </item>
    <item>
      <title>Re: AWK getline help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-getline-help/m-p/4091309#M92267</link>
      <description>&lt;!--!*#--&gt;Ah, I think I found 'the other thread'. # 1167461 right?&lt;BR /&gt;&lt;BR /&gt;Yeah, that example was wrong in syntax and possibly also in intent.&lt;BR /&gt;&lt;BR /&gt;What you really want os to build a use 'associative array' , once you found a good 'key' from the files involved.&lt;BR /&gt;Rigth not, the tables listed in the other topic do NOT show an obvious match fields.&lt;BR /&gt;But lets assume, that field #4 (just a random pick, not the right pick!) in the first input file is a lun number, and field#6 there provide useful data.&lt;BR /&gt;&lt;BR /&gt;And assume that for example field 2 in the second file is lun&lt;BR /&gt;Now you want a STUCTURE (not exact code) like:&lt;BR /&gt;&lt;BR /&gt;BEGIN {&lt;BR /&gt;    while (getline f1_line &amp;lt; "file") {&lt;BR /&gt;       split (f1_line,f1_fields,",");&lt;BR /&gt;      f1_luns[f1_fields[2]] = f1_fields[6];&lt;BR /&gt;     }&lt;BR /&gt;  }&lt;BR /&gt;{&lt;BR /&gt;: &lt;BR /&gt;if ($2 in f1_luns) { ...&lt;BR /&gt;&lt;BR /&gt;Clear?&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Wed, 24 Oct 2007 06:56:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-getline-help/m-p/4091309#M92267</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-10-24T06:56:26Z</dc:date>
    </item>
    <item>
      <title>Re: AWK getline help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-getline-help/m-p/4091310#M92268</link>
      <description>hello guys,&lt;BR /&gt;&lt;BR /&gt;Thanks for the input ...&lt;BR /&gt;&lt;BR /&gt;Hein, I am using the same code for a different purpose - I could use grep etc but still attempting to improve my awk skills.&lt;BR /&gt;&lt;BR /&gt;I have got James example to work ...&lt;BR /&gt;&lt;BR /&gt;Chris</description>
      <pubDate>Wed, 24 Oct 2007 07:09:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-getline-help/m-p/4091310#M92268</guid>
      <dc:creator>lawrenzo</dc:creator>
      <dc:date>2007-10-24T07:09:23Z</dc:date>
    </item>
    <item>
      <title>Re: AWK getline help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-getline-help/m-p/4091311#M92269</link>
      <description>I should elaborate on the task at hand though ....&lt;BR /&gt;&lt;BR /&gt;I have a file serverlistfinal.txt that contains 700 + servers in our environment.&lt;BR /&gt;&lt;BR /&gt;the file allservers.csv is a file that needs updating and has over 1000 entries therefor I need to print all rows from allservers.csv that are in serverlistfinal.txt.&lt;BR /&gt;&lt;BR /&gt;I figure I change the syntax "i=1;i&amp;lt;10;i++" as this displays the top 10 and also &amp;gt; 0 is not relevant in this code?&lt;BR /&gt;&lt;BR /&gt;Chris.</description>
      <pubDate>Wed, 24 Oct 2007 07:15:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-getline-help/m-p/4091311#M92269</guid>
      <dc:creator>lawrenzo</dc:creator>
      <dc:date>2007-10-24T07:15:28Z</dc:date>
    </item>
    <item>
      <title>Re: AWK getline help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-getline-help/m-p/4091312#M92270</link>
      <description>Hi (again) Chris:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; I figure I change the syntax "i=1;i&amp;lt;10;i++" as this displays the top 10 and also &amp;gt; 0 is not relevant in this code?&lt;BR /&gt;&lt;BR /&gt;You could count the elements read by the 'getline' and use that value as the upper bound for your later 'for' loop (of course).&lt;BR /&gt;&lt;BR /&gt;As for the:&lt;BR /&gt;&lt;BR /&gt;while (getline LINE &amp;lt; "file" &amp;gt; 0)&lt;BR /&gt;&lt;BR /&gt;...'getline' returns one (1) if it successfully reads a record;  A zero (0) is returned for EOF (end-of-file).  A -1 is returned if for instance, the file cannot be opened.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Wed, 24 Oct 2007 07:25:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-getline-help/m-p/4091312#M92270</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-10-24T07:25:13Z</dc:date>
    </item>
    <item>
      <title>Re: AWK getline help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-getline-help/m-p/4091313#M92271</link>
      <description>and I believe that&lt;BR /&gt;&lt;BR /&gt;awk 'BEGIN{while (getline LINE &amp;lt; "allservers.csv") {a[++i]=LINE}};{print $0}' serverlistfinal.txt&lt;BR /&gt;&lt;BR /&gt;is the solution&lt;BR /&gt;&lt;BR /&gt;:-)</description>
      <pubDate>Wed, 24 Oct 2007 07:25:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-getline-help/m-p/4091313#M92271</guid>
      <dc:creator>lawrenzo</dc:creator>
      <dc:date>2007-10-24T07:25:44Z</dc:date>
    </item>
    <item>
      <title>Re: AWK getline help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-getline-help/m-p/4091314#M92272</link>
      <description>Yes, that's a fine solution IF the problem is to create a simple array with all the line from that file.&lt;BR /&gt;&lt;BR /&gt;But that's so boring!&lt;BR /&gt;&lt;BR /&gt;What are you going to do with the data from that array later? Run it through a loop 'looking' for stuff?&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt; Hein, I am using the same code for a different purpose - I could use grep etc but still attempting to improve my awk skills.&lt;BR /&gt;&lt;BR /&gt;Exactly! That's precisely why I hinted you towards picking a useful key for the array, not just a list of numbers 1..end.&lt;BR /&gt;With a good key/index you can do a direct lookup suing the 'i in array' construct. You can also readily 'delete' specif array elements which are (no longer) useful.&lt;BR /&gt;&lt;BR /&gt;Check it out. It's useful and will bring you to a whole new level in awk usage, getting you ready for... perl&lt;BR /&gt;&lt;BR /&gt;:-)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 24 Oct 2007 07:39:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-getline-help/m-p/4091314#M92272</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-10-24T07:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: AWK getline help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-getline-help/m-p/4091315#M92273</link>
      <description>ok thanks for the tip Hein,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;the solution I suggested above does not actaully do what i need it to ....&lt;BR /&gt;&lt;BR /&gt;I have some good idea's here so will continue to work through my book and come up with what I need ...&lt;BR /&gt;&lt;BR /&gt;I finally want all rows found in serverlistfinal.txt to be printed with an extra field (delimited with ",")supported to another file and if the line does not exist then print not supported ie:&lt;BR /&gt;&lt;BR /&gt;Server,DNSNAME,Deployed,Active,United Kingdom,ADDRESS,REU-Unix,REU-Config,support&lt;BR /&gt;or&lt;BR /&gt;Server,DNSNAME,Deployed,Active,United Kingdom,ADDRESS,REU-Unix,REU-Config,unsupport&lt;BR /&gt;&lt;BR /&gt;make sense?&lt;BR /&gt;&lt;BR /&gt;anyhow I shall continue with this and let you know.&lt;BR /&gt;&lt;BR /&gt;cheers &lt;BR /&gt;&lt;BR /&gt;chris</description>
      <pubDate>Wed, 24 Oct 2007 07:51:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-getline-help/m-p/4091315#M92273</guid>
      <dc:creator>lawrenzo</dc:creator>
      <dc:date>2007-10-24T07:51:03Z</dc:date>
    </item>
  </channel>
</rss>

