<?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: how to extract a paragraph from a file in shell scripting in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-extract-a-paragraph-from-a-file-in-shell-scripting/m-p/5153891#M666751</link>
    <description>&amp;gt;Hein: we test variable ok ... This defaults to 'print current line if ok is true'&lt;BR /&gt;&lt;BR /&gt;Instead of having to explain this confusing code, it may be better to be explicit:&lt;BR /&gt;ok { print $0 }</description>
    <pubDate>Sun, 01 Feb 2009 01:41:59 GMT</pubDate>
    <dc:creator>Dennis Handly</dc:creator>
    <dc:date>2009-02-01T01:41:59Z</dc:date>
    <item>
      <title>how to extract a paragraph from a file in shell scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-extract-a-paragraph-from-a-file-in-shell-scripting/m-p/5153887#M666747</link>
      <description>hI gURUS,&lt;BR /&gt;&lt;BR /&gt;Am stuck up in a situation wherein a file containing the following strings,,&lt;BR /&gt;&lt;BR /&gt;filename - err.log&lt;BR /&gt;-------------------&lt;BR /&gt;Dec-31-2008&lt;BR /&gt;ASM_DISKGROUP_02&lt;BR /&gt;Jan-01-2009&lt;BR /&gt;ARCH shutting down&lt;BR /&gt;Jan-11-2009&lt;BR /&gt;SUCCESS: diskgroup ASM_DISKGROUP_02&lt;BR /&gt;Jan-31-2009&lt;BR /&gt;Alter database dismounted&lt;BR /&gt;Jan-31-2009&lt;BR /&gt;ARC0: Archival stopped&lt;BR /&gt;Feb-01-2009&lt;BR /&gt;ASM_DISKGROUP_02&lt;BR /&gt;------------------------------------------&lt;BR /&gt;I want to extract all lines from first occurence of Jan to Last occurence of Jan.&lt;BR /&gt;&lt;BR /&gt;DESIRED OUTPUT is - &lt;BR /&gt;---------------------------------&lt;BR /&gt;Jan-01-2009&lt;BR /&gt;ARCH shutting down&lt;BR /&gt;Jan-11-2009&lt;BR /&gt;SUCCESS: diskgroup ASM_DISKGROUP_02&lt;BR /&gt;Jan-31-2009&lt;BR /&gt;Alter database dismounted&lt;BR /&gt;Jan-31-2009&lt;BR /&gt;ARC0: Archival stopped&lt;BR /&gt;</description>
      <pubDate>Sat, 31 Jan 2009 14:18:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-extract-a-paragraph-from-a-file-in-shell-scripting/m-p/5153887#M666747</guid>
      <dc:creator>Mannoj</dc:creator>
      <dc:date>2009-01-31T14:18:51Z</dc:date>
    </item>
    <item>
      <title>Re: how to extract a paragraph from a file in shell scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-extract-a-paragraph-from-a-file-in-shell-scripting/m-p/5153888#M666748</link>
      <description>AWK, and other tools, offer a RANGE style condition: X,Y&lt;BR /&gt;From the time condition X becomes tru, until Y becomes true.&lt;BR /&gt;&lt;BR /&gt;For your taks that could look like as simple as:&lt;BR /&gt;&lt;BR /&gt;# awk '/^Jan/,/^Feb/' tmp.txt&lt;BR /&gt;&lt;BR /&gt;Now you may have to muck with the details like what to do with the first and last lines, or whether to worry about prior year records, or whether there is garantueed to be a start and 'next' record. So you may need:&lt;BR /&gt;&lt;BR /&gt;# awk '/^Jan.*09/,/^Feb.*09/{print prior; prior=$0}' tmp.txt&lt;BR /&gt;&lt;BR /&gt;If you know that each line with date is followed by a single additional line, then I might prefer:&lt;BR /&gt;&lt;BR /&gt;# awk '/^Jan.*09/{ print; getline; print}' tmp.txt&lt;BR /&gt;&lt;BR /&gt;But I suspect this meets your requirements best:&lt;BR /&gt;&lt;BR /&gt;awk '/-2009$/{ ok = ($1 ~ /^Jan/)? 1: 0} ok' tmp.txt&lt;BR /&gt;&lt;BR /&gt;So we look for a line ending in a year.&lt;BR /&gt;Set a flag (ok) to true to start printing if the first field in that line started with 'Jan', and false otherwise (Feb or Mar or..), to stop printing.&lt;BR /&gt;Then in a whole new program paragraph we test variable ok, and... say nothing else.&lt;BR /&gt;This defaults to 'print current line if ok is true'&lt;BR /&gt;&lt;BR /&gt;Enjoy,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Sat, 31 Jan 2009 14:52:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-extract-a-paragraph-from-a-file-in-shell-scripting/m-p/5153888#M666748</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2009-01-31T14:52:30Z</dc:date>
    </item>
    <item>
      <title>Re: how to extract a paragraph from a file in shell scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-extract-a-paragraph-from-a-file-in-shell-scripting/m-p/5153889#M666749</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;If we assume that there is only one line following each "date" line, then this will work fpr you:&lt;BR /&gt;&lt;BR /&gt;# perl -ne 'print if /^Jan-/..!/^Jan-/'  file&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Sat, 31 Jan 2009 14:57:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-extract-a-paragraph-from-a-file-in-shell-scripting/m-p/5153889#M666749</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-01-31T14:57:24Z</dc:date>
    </item>
    <item>
      <title>Re: how to extract a paragraph from a file in shell scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-extract-a-paragraph-from-a-file-in-shell-scripting/m-p/5153890#M666750</link>
      <description>Hey Hein your solution &lt;BR /&gt;&lt;BR /&gt;awk '/^Jan/,/^Feb/' tmp.txt&lt;BR /&gt;&lt;BR /&gt;suited me exactly, &lt;BR /&gt;&lt;BR /&gt;Hats off to u,,,,&lt;BR /&gt;</description>
      <pubDate>Sat, 31 Jan 2009 16:16:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-extract-a-paragraph-from-a-file-in-shell-scripting/m-p/5153890#M666750</guid>
      <dc:creator>Mannoj</dc:creator>
      <dc:date>2009-01-31T16:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: how to extract a paragraph from a file in shell scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-extract-a-paragraph-from-a-file-in-shell-scripting/m-p/5153891#M666751</link>
      <description>&amp;gt;Hein: we test variable ok ... This defaults to 'print current line if ok is true'&lt;BR /&gt;&lt;BR /&gt;Instead of having to explain this confusing code, it may be better to be explicit:&lt;BR /&gt;ok { print $0 }</description>
      <pubDate>Sun, 01 Feb 2009 01:41:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-extract-a-paragraph-from-a-file-in-shell-scripting/m-p/5153891#M666751</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-02-01T01:41:59Z</dc:date>
    </item>
  </channel>
</rss>

