<?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: Match fields in awk in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/match-fields-in-awk/m-p/5278973#M640745</link>
    <description>Well, if I understand the problem correctly you could for example double-barrel awk. First stage splits into lines, second stages looks for desired words, remembering as it goes, and printing when last match is seen or an end marker is seen. &lt;BR /&gt;Note: It is 'nice' to clear all variables after print to prevent a prior match to re-appear.&lt;BR /&gt;&lt;BR /&gt;$ awk -F ',' '{for (i = 1; i &amp;lt; NF ; i++) {print $i}}' lparcpu.out |  awk -F '=' '/lpar_name/{n=$2} /curr_&lt;BR /&gt;min_procs/{ print n,$2}'&lt;BR /&gt;juniper 2&lt;BR /&gt;&lt;BR /&gt;Or... just tell awk to treat the comma as record separator. However, now you have to 'split' the lines to find the values.&lt;BR /&gt;&lt;BR /&gt;$ awk -v RS=',' '/lpar_name/{split($0,a,"="); n=a[2]} /curr_min_procs/{split($0,a,"="); print n,a[2&lt;BR /&gt;]}' lparcpu.out&lt;BR /&gt;juniper 2&lt;BR /&gt;&lt;BR /&gt;in PERL you woudl just match for 'chunks' and  remember a part of the chunk as you go:&lt;BR /&gt;&lt;BR /&gt;$ perl -ne '$name=$1 if /lpar_name=(\w+)/; print qq($name\t$1\n) if /curr_min_procs=(\d+)/' lparcpu.out&lt;BR /&gt;juniper 2&lt;BR /&gt;&lt;BR /&gt;hth,&lt;BR /&gt;Hein&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Fri, 08 Apr 2011 12:54:45 GMT</pubDate>
    <dc:creator>Hein van den Heuvel</dc:creator>
    <dc:date>2011-04-08T12:54:45Z</dc:date>
    <item>
      <title>Match fields in awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/match-fields-in-awk/m-p/5278971#M640743</link>
      <description>I was hoping someone could help with my understanding of awk matching fields:&lt;BR /&gt;&lt;BR /&gt;I can print each field from a file:&lt;BR /&gt;&lt;BR /&gt;awk -F ',' '{for (i = 1; i &amp;lt; NF ; i++) {print $i}}' lparcpu.out&lt;BR /&gt;&lt;BR /&gt;lpar_name=juniper&lt;BR /&gt;lpar_id=18&lt;BR /&gt;curr_shared_proc_pool_id=0&lt;BR /&gt;curr_proc_mode=shared&lt;BR /&gt;curr_min_proc_units=1.0&lt;BR /&gt;curr_proc_units=2.0&lt;BR /&gt;curr_max_proc_units=4.0&lt;BR /&gt;curr_min_procs=2&lt;BR /&gt;curr_procs=2&lt;BR /&gt;curr_max_procs=4&lt;BR /&gt;curr_sharing_mode=cap&lt;BR /&gt;curr_uncap_weight=0&lt;BR /&gt;pend_shared_proc_pool_id=0&lt;BR /&gt;pend_proc_mode=shared&lt;BR /&gt;pend_min_proc_units=1.0&lt;BR /&gt;pend_proc_units=2.0&lt;BR /&gt;pend_max_proc_units=4.0&lt;BR /&gt;pend_min_procs=2&lt;BR /&gt;pend_procs=2&lt;BR /&gt;pend_max_procs=4&lt;BR /&gt;pend_sharing_mode=cap&lt;BR /&gt;pend_uncap_weight=0&lt;BR /&gt;run_proc_units=0.0&lt;BR /&gt;run_procs=0&lt;BR /&gt;' cpu.out&lt;BR /&gt;&lt;BR /&gt;how can I then search a field and print on one line:&lt;BR /&gt;&lt;BR /&gt;awk -F ',' '&lt;BR /&gt;{for (i = 1; i &amp;lt; NF ; i++)&lt;BR /&gt;$i ~ /lpar_name/ { NAME = $0 }&lt;BR /&gt;$i ~ /curr_min_proc/ { MIN = $0 }&lt;BR /&gt;print NAME,MIN}&lt;BR /&gt;' lparcpu.out&lt;BR /&gt;&lt;BR /&gt;my understanding is incorrect.&lt;BR /&gt;&lt;BR /&gt;any help much appreciated&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;Chris</description>
      <pubDate>Fri, 08 Apr 2011 09:20:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/match-fields-in-awk/m-p/5278971#M640743</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2011-04-08T09:20:34Z</dc:date>
    </item>
    <item>
      <title>Re: Match fields in awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/match-fields-in-awk/m-p/5278972#M640744</link>
      <description>Hi Chreis:&lt;BR /&gt;&lt;BR /&gt;I believe you mean (want):&lt;BR /&gt;&lt;BR /&gt;awk -F ',' '&lt;BR /&gt;/lpar_name/ { NAME = $0 }&lt;BR /&gt;/curr_min_proc/ { MIN = $0 }&lt;BR /&gt;END{print NAME,MIN}&lt;BR /&gt;' lparcpu.out&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Fri, 08 Apr 2011 09:43:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/match-fields-in-awk/m-p/5278972#M640744</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-04-08T09:43:26Z</dc:date>
    </item>
    <item>
      <title>Re: Match fields in awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/match-fields-in-awk/m-p/5278973#M640745</link>
      <description>Well, if I understand the problem correctly you could for example double-barrel awk. First stage splits into lines, second stages looks for desired words, remembering as it goes, and printing when last match is seen or an end marker is seen. &lt;BR /&gt;Note: It is 'nice' to clear all variables after print to prevent a prior match to re-appear.&lt;BR /&gt;&lt;BR /&gt;$ awk -F ',' '{for (i = 1; i &amp;lt; NF ; i++) {print $i}}' lparcpu.out |  awk -F '=' '/lpar_name/{n=$2} /curr_&lt;BR /&gt;min_procs/{ print n,$2}'&lt;BR /&gt;juniper 2&lt;BR /&gt;&lt;BR /&gt;Or... just tell awk to treat the comma as record separator. However, now you have to 'split' the lines to find the values.&lt;BR /&gt;&lt;BR /&gt;$ awk -v RS=',' '/lpar_name/{split($0,a,"="); n=a[2]} /curr_min_procs/{split($0,a,"="); print n,a[2&lt;BR /&gt;]}' lparcpu.out&lt;BR /&gt;juniper 2&lt;BR /&gt;&lt;BR /&gt;in PERL you woudl just match for 'chunks' and  remember a part of the chunk as you go:&lt;BR /&gt;&lt;BR /&gt;$ perl -ne '$name=$1 if /lpar_name=(\w+)/; print qq($name\t$1\n) if /curr_min_procs=(\d+)/' lparcpu.out&lt;BR /&gt;juniper 2&lt;BR /&gt;&lt;BR /&gt;hth,&lt;BR /&gt;Hein&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 08 Apr 2011 12:54:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/match-fields-in-awk/m-p/5278973#M640745</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2011-04-08T12:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: Match fields in awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/match-fields-in-awk/m-p/5278974#M640746</link>
      <description>&lt;!--!*#--&gt;for (i = 1; i &amp;lt; NF ; i++)&lt;BR /&gt;   $i ~ /lpar_name/ { NAME = $0 }&lt;BR /&gt;$i ~ /curr_min_proc/ { MIN = $0 }&lt;BR /&gt;print NAME,MIN}&lt;BR /&gt;&lt;BR /&gt;Not sure what you want here?&lt;BR /&gt;It seems you forgot the {} around both matches?&lt;BR /&gt;Did you really want to print the same line twice?</description>
      <pubDate>Sun, 10 Apr 2011 18:37:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/match-fields-in-awk/m-p/5278974#M640746</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2011-04-10T18:37:32Z</dc:date>
    </item>
    <item>
      <title>Re: Match fields in awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/match-fields-in-awk/m-p/5278975#M640747</link>
      <description>I guess I didnt explain what I was looking for, I want the output to appear as:&lt;BR /&gt;&lt;BR /&gt;I should mention each line in the file I am analysing appears as&lt;BR /&gt;&lt;BR /&gt;lpar_name=juniper,lpar_id=2,curr_shared_proc_pool_id=0,curr_proc_mode=shared,curr_min_proc_units=0.25,curr_proc_units=0.5,curr_max_proc_units=4.0,curr_min_procs=1,curr_procs=1,curr_max_procs=4,curr_sharing_mode=uncap,curr_uncap_weight=128,pend_shared_proc_pool_id=0,pend_proc_mode=shared,pend_min_proc_units=0.25,pend_proc_units=0.5,pend_max_proc_units=4.0,pend_min_procs=1,pend_procs=1,pend_max_procs=4,pend_sharing_mode=uncap,pend_uncap_weight=128,run_proc_units=0.5,run_procs=1,run_uncap_weight=128&lt;BR /&gt;&lt;BR /&gt;I want to extract certain fields with one command rather than running several - the current command I run is&lt;BR /&gt;&lt;BR /&gt;awk -F ',' '/'"$lpardata"'/ {split($5,a,"=");print a[2]}' lpardata=$lpardata ${CONFIG_DIR}/lparcpu.out&lt;BR /&gt;&lt;BR /&gt;thus giving me the value of $6 however I want to analyse the whole line and extract data for several parameters - in this example I want the output to be &lt;BR /&gt;&lt;BR /&gt;juniper 1&lt;BR /&gt;&lt;BR /&gt;i dont mind if the output was &lt;BR /&gt;&lt;BR /&gt;lpar_name=juniper curr_min_proc_units=1.0&lt;BR /&gt;&lt;BR /&gt;hope that makes more sense&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;Chris&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 11 Apr 2011 13:19:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/match-fields-in-awk/m-p/5278975#M640747</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2011-04-11T13:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: Match fields in awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/match-fields-in-awk/m-p/5278976#M640748</link>
      <description>Hi (again) Chris:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; I should mention each line in the file I am analysing appears as [ one big line, and ] I want to extract certain fields with one command rather than running several - the current command I run is&lt;BR /&gt;&lt;BR /&gt;&amp;gt; awk -F ',' '/'"$lpardata"'/ {split($5,a,"=");print a[2]}' lpardata=$lpardata ${CONFIG_DIR}/lparcpu.out&lt;BR /&gt;&lt;BR /&gt;&amp;gt;  I want to analyse the whole line and extract data for several parameters - in this example I want the output to be&lt;BR /&gt;&lt;BR /&gt;&amp;gt; juniper 1&lt;BR /&gt;&lt;BR /&gt;Fine, but I don't see how you get "juniper 1".&lt;BR /&gt;&lt;BR /&gt;See if this is closer to what you want:&lt;BR /&gt;&lt;BR /&gt;# awk -F "," '{for (n=1;n&lt;NF&gt;&lt;/NF&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Mon, 11 Apr 2011 13:59:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/match-fields-in-awk/m-p/5278976#M640748</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-04-11T13:59:44Z</dc:date>
    </item>
    <item>
      <title>Re: Match fields in awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/match-fields-in-awk/m-p/5278977#M640749</link>
      <description>Thanks all,&lt;BR /&gt;&lt;BR /&gt;thanks James - just what I was looking for.&lt;BR /&gt;&lt;BR /&gt;Chris</description>
      <pubDate>Mon, 11 Apr 2011 14:03:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/match-fields-in-awk/m-p/5278977#M640749</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2011-04-11T14:03:28Z</dc:date>
    </item>
  </channel>
</rss>

