<?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 and rss feeds: awk question: in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-and-rss-feeds-awk-question/m-p/3691519#M247271</link>
    <description>Hi Anu:&lt;BR /&gt;&lt;BR /&gt;Using your posted data, Rod's suggestion and mine, see if something like the following gives you what you want:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/awk -f&lt;BR /&gt;/^&lt;ITEM&gt;/{ITEM=1;n++};&lt;BR /&gt;/^&amp;lt;\/item&amp;gt;/{ITEM=0;close "tmp/out"n};&lt;BR /&gt;{if (ITEM == 1) {&lt;BR /&gt;    print "processing " $0 " in section=" n &amp;gt; "/tmp/out"n&lt;BR /&gt;}}&lt;BR /&gt;&lt;BR /&gt;...your output will appear (in this case) in three files, named "/tmp/out1", "/tmp/out2" and "/tmp/out3".&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;/ITEM&gt;</description>
    <pubDate>Wed, 14 Dec 2005 20:31:31 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2005-12-14T20:31:31Z</dc:date>
    <item>
      <title>Awk and rss feeds: awk question:</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-and-rss-feeds-awk-question/m-p/3691515#M247267</link>
      <description>Greetings..!! &lt;BR /&gt;&lt;BR /&gt;I'm trying to parse some files from a shell script. The general structure of the file is:&lt;BR /&gt;&lt;BR /&gt;..../snip/...&lt;BR /&gt;&lt;BR /&gt;&lt;ITEM&gt;&lt;BR /&gt;&lt;LINK /&gt;stuff&lt;BR /&gt;yada yada yada &lt;BR /&gt;&lt;/ITEM&gt;&lt;BR /&gt;&lt;ITEM&gt;&lt;BR /&gt;....&lt;BR /&gt;blah&lt;BR /&gt;&lt;/ITEM&gt;&lt;BR /&gt;&lt;ITEM&gt;&lt;BR /&gt;.. and so forth...&lt;BR /&gt;&lt;BR /&gt;I want to extract stuff between lines that begin with &lt;ITEM&gt; and ends with &lt;/ITEM&gt;, and save each extraction's output to a file, evoke a function to process that file, and so forth, until there are no more such sections left in the input file. &lt;BR /&gt;&lt;BR /&gt;I've this so far: &lt;BR /&gt;&lt;BR /&gt;cat in.file | awk '/^&lt;ITEM&gt;/{&lt;BR /&gt;getline;&lt;BR /&gt;while ( $0 !~ "^&amp;lt;\/item&amp;gt;" ) {&lt;BR /&gt;print $0 &lt;BR /&gt;getline;&lt;BR /&gt;}&lt;BR /&gt;exit ;&lt;BR /&gt;}' &amp;gt;&amp;gt; /tmp/out.$$&lt;BR /&gt;&lt;BR /&gt;This extracts only the 1st section of infile between &lt;ITEM&gt; and &lt;/ITEM&gt;. &lt;BR /&gt;&lt;BR /&gt;Now, without "exit;", it extracts all sections in infile which start and end with &lt;ITEM&gt; and &lt;/ITEM&gt; respectively. &lt;BR /&gt;&lt;BR /&gt;Any help will be much appreciated. &lt;BR /&gt;&lt;BR /&gt;--AM&lt;/ITEM&gt;&lt;/ITEM&gt;</description>
      <pubDate>Wed, 14 Dec 2005 14:05:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-and-rss-feeds-awk-question/m-p/3691515#M247267</guid>
      <dc:creator>Anu Mathew</dc:creator>
      <dc:date>2005-12-14T14:05:54Z</dc:date>
    </item>
    <item>
      <title>Re: Awk and rss feeds: awk question:</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-and-rss-feeds-awk-question/m-p/3691516#M247268</link>
      <description>Rather then copy each section to a seperate file, why not process each section as it appears. For instance-&lt;BR /&gt; &lt;BR /&gt;awk -f awkprog in.file&lt;BR /&gt; &lt;BR /&gt;awkprog contains-&lt;BR /&gt;/^&lt;ITEM&gt;/{ITEM=1};&lt;BR /&gt;/^&amp;lt;\/item&amp;gt;/{ITEM=0};&lt;BR /&gt;ITEM == 1 { print "processing " $0 " now"}&lt;BR /&gt; &lt;BR /&gt;If you plan to do multi-level exploded of sections within sections, then "perl" might be a better tool for parsing and processing the file.&lt;BR /&gt; &lt;BR /&gt;my 2 cents&lt;BR /&gt; &lt;BR /&gt;Rod Hills&lt;/ITEM&gt;</description>
      <pubDate>Wed, 14 Dec 2005 14:57:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-and-rss-feeds-awk-question/m-p/3691516#M247268</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2005-12-14T14:57:49Z</dc:date>
    </item>
    <item>
      <title>Re: Awk and rss feeds: awk question:</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-and-rss-feeds-awk-question/m-p/3691517#M247269</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;You can redirect in 'awk'.  Remember to close files not in use as is always good practice.  For example:&lt;BR /&gt;&lt;BR /&gt;# awk '{print $0 &amp;gt;&amp;gt; "/tmp/output"};END{close "/tmp/output"}' /etc/hosts&lt;BR /&gt;&lt;BR /&gt;...would copy '/etc/hosts' to '/tmp/output'.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 14 Dec 2005 15:11:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-and-rss-feeds-awk-question/m-p/3691517#M247269</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2005-12-14T15:11:07Z</dc:date>
    </item>
    <item>
      <title>Re: Awk and rss feeds: awk question:</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-and-rss-feeds-awk-question/m-p/3691518#M247270</link>
      <description>Thanks.&lt;BR /&gt;&lt;BR /&gt;Rodney, that would be somewhat similar to: &lt;BR /&gt;&lt;BR /&gt; awk '/&lt;ITEM&gt;/,/&amp;lt;\/item&amp;gt;/ {print "processing " $0 " now"}' inputfile &lt;BR /&gt;&lt;BR /&gt;For every occurence of &lt;ITEM&gt; and &lt;/ITEM&gt;, I want to grab the stuff in between them, to either run a script, or say to save it as as files "out.1, out.2.. etc."&lt;/ITEM&gt;</description>
      <pubDate>Wed, 14 Dec 2005 18:54:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-and-rss-feeds-awk-question/m-p/3691518#M247270</guid>
      <dc:creator>Anu Mathew</dc:creator>
      <dc:date>2005-12-14T18:54:41Z</dc:date>
    </item>
    <item>
      <title>Re: Awk and rss feeds: awk question:</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-and-rss-feeds-awk-question/m-p/3691519#M247271</link>
      <description>Hi Anu:&lt;BR /&gt;&lt;BR /&gt;Using your posted data, Rod's suggestion and mine, see if something like the following gives you what you want:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/awk -f&lt;BR /&gt;/^&lt;ITEM&gt;/{ITEM=1;n++};&lt;BR /&gt;/^&amp;lt;\/item&amp;gt;/{ITEM=0;close "tmp/out"n};&lt;BR /&gt;{if (ITEM == 1) {&lt;BR /&gt;    print "processing " $0 " in section=" n &amp;gt; "/tmp/out"n&lt;BR /&gt;}}&lt;BR /&gt;&lt;BR /&gt;...your output will appear (in this case) in three files, named "/tmp/out1", "/tmp/out2" and "/tmp/out3".&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;/ITEM&gt;</description>
      <pubDate>Wed, 14 Dec 2005 20:31:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-and-rss-feeds-awk-question/m-p/3691519#M247271</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2005-12-14T20:31:31Z</dc:date>
    </item>
    <item>
      <title>Re: Awk and rss feeds: awk question:</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-and-rss-feeds-awk-question/m-p/3691520#M247272</link>
      <description>Hi Anu,&lt;BR /&gt;Hope this might help:&lt;BR /&gt;&lt;BR /&gt;cat in.file | awk '/^&lt;ITEM&gt;/{&lt;BR /&gt;getline;&lt;BR /&gt;i++;&lt;BR /&gt;while ( $0 !~ "^&amp;lt;\/item&amp;gt;" ) {&lt;BR /&gt; print $0 &amp;gt;&amp;gt; "out." i&lt;BR /&gt; getline;&lt;BR /&gt;}&lt;BR /&gt;close "out." i&lt;BR /&gt;}' &lt;BR /&gt;&lt;BR /&gt;Incase 'i' doesn't start from '1', use this:&lt;BR /&gt;&lt;BR /&gt;cat in.file | awk 'begin{i=0}/^&lt;ITEM&gt;/{&lt;BR /&gt;getline;&lt;BR /&gt;i++;&lt;BR /&gt;while ( $0 !~ "^&amp;lt;\/item&amp;gt;" ) {&lt;BR /&gt; print $0 &amp;gt;&amp;gt; "out." i&lt;BR /&gt; getline;&lt;BR /&gt;}&lt;BR /&gt;close "out." i&lt;BR /&gt;}' &lt;BR /&gt;&lt;/ITEM&gt;&lt;/ITEM&gt;</description>
      <pubDate>Thu, 15 Dec 2005 14:15:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-and-rss-feeds-awk-question/m-p/3691520#M247272</guid>
      <dc:creator>Srini Jay</dc:creator>
      <dc:date>2005-12-15T14:15:49Z</dc:date>
    </item>
  </channel>
</rss>

