<?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: Consecutive lines in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/consecutive-lines/m-p/5036822#M95346</link>
    <description>Pert, I like the solution you list as favourite also for anyting that is slightly more complex than a simple range.&lt;BR /&gt;&lt;BR /&gt;The bare 'out' is a little obscure, but effective.&lt;BR /&gt;It is of course a test for the variable out and if true the (empty) statement following it is executed, the default statement being a print of the current line.&lt;BR /&gt;Much like: (out!=0) { print $0 }&lt;BR /&gt;&lt;BR /&gt;You can make it slight more tricky, obscure and shorter by carefully arranging the test and sets:&lt;BR /&gt;&lt;BR /&gt;awk '/^E2/ {out=0} out; /^E2 002/ {out=1}' tmp.txt&lt;BR /&gt;&lt;BR /&gt;:-)&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
    <pubDate>Wed, 28 Mar 2007 11:00:59 GMT</pubDate>
    <dc:creator>Hein van den Heuvel</dc:creator>
    <dc:date>2007-03-28T11:00:59Z</dc:date>
    <item>
      <title>Consecutive lines</title>
      <link>https://community.hpe.com/t5/operating-system-linux/consecutive-lines/m-p/5036815#M95339</link>
      <description>cat file1.txt&lt;BR /&gt;E1 001&lt;BR /&gt;a a1&lt;BR /&gt;b b1&lt;BR /&gt;E2 002&lt;BR /&gt;a a1&lt;BR /&gt;aa  a2&lt;BR /&gt;b b1&lt;BR /&gt;c c1&lt;BR /&gt;cc c2&lt;BR /&gt;E3 003&lt;BR /&gt;a a1&lt;BR /&gt;aa a2&lt;BR /&gt;&lt;BR /&gt;I need to get the lines between E2 and E3 using awk or sed.&lt;BR /&gt;10 points for the best answer.</description>
      <pubDate>Tue, 27 Mar 2007 22:59:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/consecutive-lines/m-p/5036815#M95339</guid>
      <dc:creator>maliaka</dc:creator>
      <dc:date>2007-03-27T22:59:14Z</dc:date>
    </item>
    <item>
      <title>Re: Consecutive lines</title>
      <link>https://community.hpe.com/t5/operating-system-linux/consecutive-lines/m-p/5036816#M95340</link>
      <description>sed -n -e '/E2/,/E3/p'&lt;BR /&gt;This will get the lines including E2 and E3.&lt;BR /&gt;&lt;BR /&gt;If you don't want them, you could use more complex logic in sed that would be hard to understand.  (I couldn't get /E2/+1 to work.)&lt;BR /&gt;&lt;BR /&gt;Or just use grep -v:&lt;BR /&gt;sed -n -e '/E2/,/E3/p' file | grep -v -e E2 -e E3</description>
      <pubDate>Wed, 28 Mar 2007 00:37:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/consecutive-lines/m-p/5036816#M95340</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-03-28T00:37:03Z</dc:date>
    </item>
    <item>
      <title>Re: Consecutive lines</title>
      <link>https://community.hpe.com/t5/operating-system-linux/consecutive-lines/m-p/5036817#M95341</link>
      <description>Thanks Dennis,&lt;BR /&gt;&lt;BR /&gt;What if the file contains the following:&lt;BR /&gt;&lt;BR /&gt;E2 002&lt;BR /&gt;a a1&lt;BR /&gt;aa a2&lt;BR /&gt;b b1&lt;BR /&gt;c c1&lt;BR /&gt;cc c2&lt;BR /&gt;E2 xxx&lt;BR /&gt;&lt;BR /&gt;Notice, E2 is repeated twice but the numbers next to the E2 are different numbers. Let's assume that we know the first E2 has 002 but we don't know what is the number for the next E2? How do you go about getting the lines between them?&lt;BR /&gt;&lt;BR /&gt;Thanks again</description>
      <pubDate>Wed, 28 Mar 2007 06:55:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/consecutive-lines/m-p/5036817#M95341</guid>
      <dc:creator>maliaka</dc:creator>
      <dc:date>2007-03-28T06:55:39Z</dc:date>
    </item>
    <item>
      <title>Re: Consecutive lines</title>
      <link>https://community.hpe.com/t5/operating-system-linux/consecutive-lines/m-p/5036818#M95342</link>
      <description>I cut the file in my last post, sorry. It contains these entries. I need to get the lines for E2 002 block only.&lt;BR /&gt;&lt;BR /&gt;E2 xxx&lt;BR /&gt;a a1&lt;BR /&gt;b b1&lt;BR /&gt;E2 002&lt;BR /&gt;a a1&lt;BR /&gt;aa a2&lt;BR /&gt;b b1&lt;BR /&gt;c c1&lt;BR /&gt;cc c2&lt;BR /&gt;E2 xxx&lt;BR /&gt;a a1&lt;BR /&gt;aa a2</description>
      <pubDate>Wed, 28 Mar 2007 06:59:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/consecutive-lines/m-p/5036818#M95342</guid>
      <dc:creator>maliaka</dc:creator>
      <dc:date>2007-03-28T06:59:35Z</dc:date>
    </item>
    <item>
      <title>Re: Consecutive lines</title>
      <link>https://community.hpe.com/t5/operating-system-linux/consecutive-lines/m-p/5036819#M95343</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; Let's assume that we know the first E2 has 002 but we don't know what is the number for the next E2? How do you go about getting the lines between them?&lt;BR /&gt;&lt;BR /&gt;Dennis's solution works again.  Simply qualify a bit more of the starting pattern:&lt;BR /&gt;&lt;BR /&gt;# sed -n -e '/E2 002/,/E2/p' file&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 28 Mar 2007 07:09:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/consecutive-lines/m-p/5036819#M95343</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-03-28T07:09:55Z</dc:date>
    </item>
    <item>
      <title>Re: Consecutive lines</title>
      <link>https://community.hpe.com/t5/operating-system-linux/consecutive-lines/m-p/5036820#M95344</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;my favourite solution follows.&lt;BR /&gt;- refine your start/end condition as required&lt;BR /&gt;- drop the 'next' statement, when you want to include the lines including the limit condition&lt;BR /&gt;&lt;BR /&gt;awk '/^E2 002/ {out=1; next}&lt;BR /&gt;/^E2/ {out=0; next}&lt;BR /&gt;out' file1.txt&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
      <pubDate>Wed, 28 Mar 2007 08:04:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/consecutive-lines/m-p/5036820#M95344</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2007-03-28T08:04:31Z</dc:date>
    </item>
    <item>
      <title>Re: Consecutive lines</title>
      <link>https://community.hpe.com/t5/operating-system-linux/consecutive-lines/m-p/5036821#M95345</link>
      <description>Try the ex(1) construct below:&lt;BR /&gt;&lt;BR /&gt;# ex -s +'/^E2 002$/+1;/^E/-1 p | q!' file1.txt&lt;BR /&gt;&lt;BR /&gt;It prints all lines that fall between the pattern that starts with "E2 002" and the pattern that ends with "E[23]" etc.&lt;BR /&gt;&lt;BR /&gt;~cheers</description>
      <pubDate>Wed, 28 Mar 2007 10:27:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/consecutive-lines/m-p/5036821#M95345</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-03-28T10:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: Consecutive lines</title>
      <link>https://community.hpe.com/t5/operating-system-linux/consecutive-lines/m-p/5036822#M95346</link>
      <description>Pert, I like the solution you list as favourite also for anyting that is slightly more complex than a simple range.&lt;BR /&gt;&lt;BR /&gt;The bare 'out' is a little obscure, but effective.&lt;BR /&gt;It is of course a test for the variable out and if true the (empty) statement following it is executed, the default statement being a print of the current line.&lt;BR /&gt;Much like: (out!=0) { print $0 }&lt;BR /&gt;&lt;BR /&gt;You can make it slight more tricky, obscure and shorter by carefully arranging the test and sets:&lt;BR /&gt;&lt;BR /&gt;awk '/^E2/ {out=0} out; /^E2 002/ {out=1}' tmp.txt&lt;BR /&gt;&lt;BR /&gt;:-)&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Wed, 28 Mar 2007 11:00:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/consecutive-lines/m-p/5036822#M95346</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-03-28T11:00:59Z</dc:date>
    </item>
    <item>
      <title>Re: Consecutive lines</title>
      <link>https://community.hpe.com/t5/operating-system-linux/consecutive-lines/m-p/5036823#M95347</link>
      <description>You guys are awesome! &lt;BR /&gt;Thanks</description>
      <pubDate>Wed, 28 Mar 2007 22:07:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/consecutive-lines/m-p/5036823#M95347</guid>
      <dc:creator>maliaka</dc:creator>
      <dc:date>2007-03-28T22:07:55Z</dc:date>
    </item>
  </channel>
</rss>

