<?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: parser multiple lines in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/parser-multiple-lines/m-p/3746236#M101467</link>
    <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;Oh, and having named my script:&lt;BR /&gt;&lt;BR /&gt;# parse.pl&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;    print if $tog == 1;&lt;BR /&gt;    $tog = 0 if m/^\*/;&lt;BR /&gt;    next if ($id = m/Unix/);&lt;BR /&gt;    if (m/Total Views:(\d+)/) {&lt;BR /&gt;        if ($1 &amp;gt; 10) {&lt;BR /&gt;            $tog = 1;&lt;BR /&gt;            print $id, $_ ;&lt;BR /&gt;        }&lt;BR /&gt;    }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;...run as:&lt;BR /&gt;&lt;BR /&gt;./parse.pl filename&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF,,,</description>
    <pubDate>Tue, 07 Mar 2006 13:22:11 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2006-03-07T13:22:11Z</dc:date>
    <item>
      <title>parser multiple lines</title>
      <link>https://community.hpe.com/t5/operating-system-linux/parser-multiple-lines/m-p/3746232#M101463</link>
      <description>I have a file like this&lt;BR /&gt;&lt;BR /&gt;*******************************************&lt;BR /&gt;Unix ID:XXX&lt;BR /&gt;Total Views:5&lt;BR /&gt;  content....&lt;BR /&gt;*******************************************&lt;BR /&gt;Unix ID:YYY&lt;BR /&gt;Total Views:12&lt;BR /&gt;  content....&lt;BR /&gt;********************************************&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I want to find whose view is greater than 10 and extract his data.&lt;BR /&gt;&lt;BR /&gt;For example above, the output should look like&lt;BR /&gt;&lt;BR /&gt;Unix ID:YYY&lt;BR /&gt;Total Views:12&lt;BR /&gt;  content....&lt;BR /&gt;&lt;BR /&gt;can awk or whatever..take multiple lines?&lt;BR /&gt;&lt;BR /&gt;thank you&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 07 Mar 2006 12:10:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/parser-multiple-lines/m-p/3746232#M101463</guid>
      <dc:creator>Gemini_2</dc:creator>
      <dc:date>2006-03-07T12:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: parser multiple lines</title>
      <link>https://community.hpe.com/t5/operating-system-linux/parser-multiple-lines/m-p/3746233#M101464</link>
      <description>There are several prior advice in the ITRC forum about 'grepping fr paragraphs' and the likes. Check those out!&lt;BR /&gt;Google: +awk +paragraph +site:itrc.hp.com&lt;BR /&gt;&lt;BR /&gt;Here is how I might solve your question with a '1 liner'.&lt;BR /&gt;&lt;BR /&gt;awk '/Total V/{split($0,a,":"); if (a[2] &amp;gt;10) {print unix}} /^\*/{a[2]=0} {if(a[2]&amp;gt;10){print} else {unix=$0}}' x &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;In details:&lt;BR /&gt;&lt;BR /&gt;==&amp;gt; /Total V/{split($0,a,":"); &lt;BR /&gt;If we see the line beginning with total then split using a colon or get the number in array element a[2].&lt;BR /&gt;&lt;BR /&gt;==&amp;gt; if (a[2] &amp;gt;10) {print unix}}&lt;BR /&gt;If that array element is larger than 10, print a stashed away prior line(s).&lt;BR /&gt;&lt;BR /&gt;==&amp;gt;  /^\*/{a[2]=0} &lt;BR /&gt;If we see line starting with *, then indicate being done by clearing the counter.&lt;BR /&gt;&lt;BR /&gt;==&amp;gt; {if(a[2]&amp;gt;10){print} else {unix=$0}}&lt;BR /&gt;For every line, print it if count is high, else stash away line in case it happens to become next "Unix ID"&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Good luck,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Tue, 07 Mar 2006 13:01:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/parser-multiple-lines/m-p/3746233#M101464</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2006-03-07T13:01:39Z</dc:date>
    </item>
    <item>
      <title>Re: parser multiple lines</title>
      <link>https://community.hpe.com/t5/operating-system-linux/parser-multiple-lines/m-p/3746234#M101465</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;You can use the awk construct given below. :&lt;BR /&gt;&lt;BR /&gt;==============mycmds.awk=====================&lt;BR /&gt;$0 ~ /^Unix ID/ {       &lt;BR /&gt;    prev=$0&lt;BR /&gt;    getline&lt;BR /&gt;    val=z[split($NF,z,":")]&lt;BR /&gt;    curr=$0&lt;BR /&gt;    getline&lt;BR /&gt;    if(val&amp;gt;10) {&lt;BR /&gt;        printf("%s\n%s\n%s\n",prev,curr,$0) }&lt;BR /&gt;}&lt;BR /&gt;=============================================&lt;BR /&gt;&lt;BR /&gt;Put all the above commands in a file named mycmds.awk and execute as:&lt;BR /&gt;&lt;BR /&gt;# awk -f mycmds.awk &lt;YOUR_INPUT_FILE&gt;&lt;BR /&gt;&lt;BR /&gt;cheers!&lt;/YOUR_INPUT_FILE&gt;</description>
      <pubDate>Tue, 07 Mar 2006 13:15:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/parser-multiple-lines/m-p/3746234#M101465</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2006-03-07T13:15:26Z</dc:date>
    </item>
    <item>
      <title>Re: parser multiple lines</title>
      <link>https://community.hpe.com/t5/operating-system-linux/parser-multiple-lines/m-p/3746235#M101466</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;This would work for you:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;    print if $tog == 1;&lt;BR /&gt;    $tog = 0 if m/^\*/;&lt;BR /&gt;    next if ($id = m/Unix/);&lt;BR /&gt;    if (m/Total Views:(\d+)/) {&lt;BR /&gt;        if ($1 &amp;gt; 10) {&lt;BR /&gt;            $tog = 1;&lt;BR /&gt;            print $id, $_ ;&lt;BR /&gt;        }&lt;BR /&gt;    }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 07 Mar 2006 13:17:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/parser-multiple-lines/m-p/3746235#M101466</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-03-07T13:17:39Z</dc:date>
    </item>
    <item>
      <title>Re: parser multiple lines</title>
      <link>https://community.hpe.com/t5/operating-system-linux/parser-multiple-lines/m-p/3746236#M101467</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;Oh, and having named my script:&lt;BR /&gt;&lt;BR /&gt;# parse.pl&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;    print if $tog == 1;&lt;BR /&gt;    $tog = 0 if m/^\*/;&lt;BR /&gt;    next if ($id = m/Unix/);&lt;BR /&gt;    if (m/Total Views:(\d+)/) {&lt;BR /&gt;        if ($1 &amp;gt; 10) {&lt;BR /&gt;            $tog = 1;&lt;BR /&gt;            print $id, $_ ;&lt;BR /&gt;        }&lt;BR /&gt;    }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;...run as:&lt;BR /&gt;&lt;BR /&gt;./parse.pl filename&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF,,,</description>
      <pubDate>Tue, 07 Mar 2006 13:22:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/parser-multiple-lines/m-p/3746236#M101467</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-03-07T13:22:11Z</dc:date>
    </item>
    <item>
      <title>Re: parser multiple lines</title>
      <link>https://community.hpe.com/t5/operating-system-linux/parser-multiple-lines/m-p/3746237#M101468</link>
      <description>thanks everyone for your suggestions. &lt;BR /&gt;&lt;BR /&gt;let me give a try!&lt;BR /&gt;&lt;BR /&gt;I assigned everyone some points!!&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 07 Mar 2006 14:52:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/parser-multiple-lines/m-p/3746237#M101468</guid>
      <dc:creator>Gemini_2</dc:creator>
      <dc:date>2006-03-07T14:52:09Z</dc:date>
    </item>
  </channel>
</rss>

