<?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: sorting and formating script - for scripting champions! in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/sorting-and-formating-script-for-scripting-champions/m-p/2617673#M925239</link>
    <description>Hi Bill&lt;BR /&gt;For a start grep out each section to a file.&lt;BR /&gt;&lt;BR /&gt;ie.&lt;BR /&gt;cat file.xml | grep Name &amp;gt; /tmp/bars&lt;BR /&gt;cat file.xml | grep Town &amp;gt; /tmp/town&lt;BR /&gt;&lt;BR /&gt;Etc&lt;BR /&gt;&lt;BR /&gt;search and replace (sed) the &amp;lt; with spaces.&lt;BR /&gt;Awk out the name field and output to files&lt;BR /&gt;one for each bit of data.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Paula&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Paula&lt;BR /&gt;</description>
    <pubDate>Tue, 20 Nov 2001 16:35:01 GMT</pubDate>
    <dc:creator>Paula J Frazer-Campbell</dc:creator>
    <dc:date>2001-11-20T16:35:01Z</dc:date>
    <item>
      <title>sorting and formating script - for scripting champions!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sorting-and-formating-script-for-scripting-champions/m-p/2617669#M925235</link>
      <description>Hi,&lt;BR /&gt;I've got an xml file as follows:&lt;BR /&gt;&lt;BR /&gt; &lt;BAR&gt;&lt;BR /&gt; &lt;NAME&gt;StagsHead&lt;BR /&gt; &lt;/NAME&gt;&lt;BR /&gt;  &lt;TOWN&gt;BigTown&lt;BR /&gt;  &lt;/TOWN&gt;&lt;BR /&gt;  &lt;ROAD&gt;Main St.&lt;BR /&gt;  &lt;/ROAD&gt;&lt;BR /&gt;  &lt;NUMBER&gt;5&lt;BR /&gt;  &lt;/NUMBER&gt;&lt;BR /&gt;  &lt;OWNER&gt;johnny walker&lt;BR /&gt;  &lt;/OWNER&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;DRINK&gt;&lt;BR /&gt; &lt;ID&gt;1&lt;BR /&gt; &lt;/ID&gt;&lt;BR /&gt; &lt;TYPE&gt;Stout&lt;BR /&gt; &lt;/TYPE&gt;&lt;BR /&gt; &lt;TAPS&gt;5&lt;BR /&gt; &lt;/TAPS&gt;&lt;BR /&gt; &lt;ALCO&gt;4&lt;BR /&gt; &lt;/ALCO&gt;&lt;BR /&gt;&lt;/DRINK&gt;        &lt;BR /&gt;&lt;BR /&gt;&lt;/BAR&gt;&lt;BR /&gt;&lt;BR /&gt;With lots of Drink sections.&lt;BR /&gt;&lt;BR /&gt;I'd like to format all this data as follows:&lt;BR /&gt;&lt;BR /&gt;Bar: StagsHead&lt;BR /&gt;&lt;BR /&gt;Drink === i d === i d === i d ===&lt;BR /&gt;0-31  --- yes --- no  --- yes ---&lt;BR /&gt;31-64 --- no  --- yes --- yes ---&lt;BR /&gt;&lt;BR /&gt;and this way too:&lt;BR /&gt;&lt;BR /&gt;Drink: Stout&lt;BR /&gt;&lt;BR /&gt;Taps === StagsHead === NagsHead === Chocolate&lt;BR /&gt;5    --- 5         ---    X     ---    X&lt;BR /&gt;4    --- X         ---    4     ---    X&lt;BR /&gt;3    --- X         ---    X     ---    3&lt;BR /&gt;&lt;BR /&gt;etc..&lt;BR /&gt;&lt;BR /&gt;Complicated.. so where to start.&lt;BR /&gt;&lt;BR /&gt;I'm thinking for a start to have an option to the script -perbar and -perdrink&lt;BR /&gt;&lt;BR /&gt;Anyway,&lt;BR /&gt;Interested to see what comes up!&lt;BR /&gt;All replies rewarded.&lt;BR /&gt;&lt;BR /&gt;Later,&lt;BR /&gt;Bill</description>
      <pubDate>Tue, 20 Nov 2001 16:02:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sorting-and-formating-script-for-scripting-champions/m-p/2617669#M925235</guid>
      <dc:creator>Bill McNAMARA_1</dc:creator>
      <dc:date>2001-11-20T16:02:02Z</dc:date>
    </item>
    <item>
      <title>Re: sorting and formating script - for scripting champions!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sorting-and-formating-script-for-scripting-champions/m-p/2617670#M925236</link>
      <description>Bill,&lt;BR /&gt;&lt;BR /&gt;It's time to jump on the perl beerwagon:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://wwwx.netheaven.com/~coopercc/xmlparser/Parser.html" target="_blank"&gt;http://wwwx.netheaven.com/~coopercc/xmlparser/Parser.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Tue, 20 Nov 2001 16:05:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sorting-and-formating-script-for-scripting-champions/m-p/2617670#M925236</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2001-11-20T16:05:43Z</dc:date>
    </item>
    <item>
      <title>Re: sorting and formating script - for scripting champions!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sorting-and-formating-script-for-scripting-champions/m-p/2617671#M925237</link>
      <description>never used perl Harry, &lt;BR /&gt;can you give me an example..&lt;BR /&gt;I have it installed for what it's worth!&lt;BR /&gt;(except for that module..)&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Bill&lt;BR /&gt;</description>
      <pubDate>Tue, 20 Nov 2001 16:07:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sorting-and-formating-script-for-scripting-champions/m-p/2617671#M925237</guid>
      <dc:creator>Bill McNAMARA_1</dc:creator>
      <dc:date>2001-11-20T16:07:59Z</dc:date>
    </item>
    <item>
      <title>Re: sorting and formating script - for scripting champions!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sorting-and-formating-script-for-scripting-champions/m-p/2617672#M925238</link>
      <description>Perl is definitely the way to go, I gave up on shell scripting a long time ago :)  If you know a bit of C, perl isn't hard to pick up at all.&lt;BR /&gt;&lt;BR /&gt;There are perl modules available on &lt;A href="http://www.cpan.org" target="_blank"&gt;www.cpan.org&lt;/A&gt; for parsing XML, so you won't have to re-invent the wheel completely.&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Steve</description>
      <pubDate>Tue, 20 Nov 2001 16:27:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sorting-and-formating-script-for-scripting-champions/m-p/2617672#M925238</guid>
      <dc:creator>Steven Gillard_2</dc:creator>
      <dc:date>2001-11-20T16:27:15Z</dc:date>
    </item>
    <item>
      <title>Re: sorting and formating script - for scripting champions!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sorting-and-formating-script-for-scripting-champions/m-p/2617673#M925239</link>
      <description>Hi Bill&lt;BR /&gt;For a start grep out each section to a file.&lt;BR /&gt;&lt;BR /&gt;ie.&lt;BR /&gt;cat file.xml | grep Name &amp;gt; /tmp/bars&lt;BR /&gt;cat file.xml | grep Town &amp;gt; /tmp/town&lt;BR /&gt;&lt;BR /&gt;Etc&lt;BR /&gt;&lt;BR /&gt;search and replace (sed) the &amp;lt; with spaces.&lt;BR /&gt;Awk out the name field and output to files&lt;BR /&gt;one for each bit of data.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Paula&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Paula&lt;BR /&gt;</description>
      <pubDate>Tue, 20 Nov 2001 16:35:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sorting-and-formating-script-for-scripting-champions/m-p/2617673#M925239</guid>
      <dc:creator>Paula J Frazer-Campbell</dc:creator>
      <dc:date>2001-11-20T16:35:01Z</dc:date>
    </item>
    <item>
      <title>Re: sorting and formating script - for scripting champions!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sorting-and-formating-script-for-scripting-champions/m-p/2617674#M925240</link>
      <description>Seems we need to do quite some twists. &lt;BR /&gt;&lt;BR /&gt;1. Get all the names&lt;BR /&gt;&lt;BR /&gt;grep "&lt;NAME&gt;" thisfile |awk '{FS="&amp;gt;";print $2}'&lt;BR /&gt;&lt;BR /&gt;2. Now get each block categorized under this above name.&lt;BR /&gt;&lt;BR /&gt;For i in "the above"&lt;BR /&gt;do&lt;BR /&gt;sed -n '/'$i'/,/\&amp;lt;\/Bar\&amp;gt;/p' bar &amp;gt; /tmp/name$$&lt;BR /&gt;call_another_function on /tmp/name$$&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;3. This another_function will need to filter out drinks like we filtered out Names in the above and gets properties of each drink. It would be cumbersome if we don't use sed and awk's here.Then a simple printf statement would format the results.&lt;BR /&gt;&lt;BR /&gt;You will definitely need a couple of coffees and may be some drinks mentioned in your xml before you can get this working.&lt;BR /&gt;&lt;BR /&gt;-Sri&lt;/NAME&gt;</description>
      <pubDate>Tue, 20 Nov 2001 17:03:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sorting-and-formating-script-for-scripting-champions/m-p/2617674#M925240</guid>
      <dc:creator>Sridhar Bhaskarla</dc:creator>
      <dc:date>2001-11-20T17:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: sorting and formating script - for scripting champions!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sorting-and-formating-script-for-scripting-champions/m-p/2617675#M925241</link>
      <description>Eek! Doing this via shell is probably not the best way to do this - the best way would be to use some form of relational database (eg mysql) or use an XML parser for either perl *spit* or C.&lt;BR /&gt;&lt;BR /&gt;If you *have* to use shell then I'd suggest using awk to convert to a halfway house type format of file and then using normal shell tools to do the rest.&lt;BR /&gt;&lt;BR /&gt;You could use awk similar to below to get the fields out:&lt;BR /&gt;awk '&lt;BR /&gt;/\&lt;BAR&gt;/,/\&amp;lt;\/bar\&amp;gt;/&lt;BR /&gt;{&lt;BR /&gt;   do {&lt;BR /&gt;      if ( $0 ~ "&lt;NAME&gt;" ) print "Name: " substr($0, index($0,"&lt;NAME&gt;")+6);&lt;BR /&gt;      getline;&lt;BR /&gt;   } while ($0 != "&lt;/NAME&gt;)&lt;BR /&gt;}' bar.xml&lt;BR /&gt;&lt;BR /&gt;Of course this will fail the xml is like:&lt;BR /&gt;&lt;NAME&gt;The aardvark's head&lt;/NAME&gt;&lt;BR /&gt;&lt;BR /&gt;dave&lt;BR /&gt;&lt;BR /&gt;dave&lt;/NAME&gt;&lt;/BAR&gt;</description>
      <pubDate>Tue, 20 Nov 2001 17:52:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sorting-and-formating-script-for-scripting-champions/m-p/2617675#M925241</guid>
      <dc:creator>David Lodge</dc:creator>
      <dc:date>2001-11-20T17:52:05Z</dc:date>
    </item>
    <item>
      <title>Re: sorting and formating script - for scripting champions!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sorting-and-formating-script-for-scripting-champions/m-p/2617676#M925242</link>
      <description>Hello Bill,&lt;BR /&gt;&lt;BR /&gt;A task for perl + Bundle::XML.&lt;BR /&gt;&lt;BR /&gt;This Bundle downloads a lot of XML modules from CPAN and allows you to manipulate XML data (to be honest, I started writing your script, but timing issues here prevented me from completing...).&lt;BR /&gt;&lt;BR /&gt;To install Bundle::XML&lt;BR /&gt;&lt;BR /&gt;perl -MCPAN -e "install Bundle::XML"&lt;BR /&gt;&lt;BR /&gt;(as root)&lt;BR /&gt;&lt;BR /&gt;Then, man XML::Parser to see an example on how to do it.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Paga&lt;BR /&gt;</description>
      <pubDate>Tue, 20 Nov 2001 20:18:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sorting-and-formating-script-for-scripting-champions/m-p/2617676#M925242</guid>
      <dc:creator>Marco Paganini</dc:creator>
      <dc:date>2001-11-20T20:18:03Z</dc:date>
    </item>
    <item>
      <title>Re: sorting and formating script - for scripting champions!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sorting-and-formating-script-for-scripting-champions/m-p/2617677#M925243</link>
      <description>Find attached a 50 line perl routine that will parse (without the XML module) your data file and generate one of the reports shown.&lt;BR /&gt;&lt;BR /&gt;The programs assumes that  the syntax of the xml file is correct and that the tags are all unique.&lt;BR /&gt;&lt;BR /&gt;The data is slurpped into a hash variable  and it should be relativelly easy to reformat the data into whatever report you would like..&lt;BR /&gt;&lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Tue, 20 Nov 2001 21:34:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sorting-and-formating-script-for-scripting-champions/m-p/2617677#M925243</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2001-11-20T21:34:34Z</dc:date>
    </item>
    <item>
      <title>Re: sorting and formating script - for scripting champions!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sorting-and-formating-script-for-scripting-champions/m-p/2617678#M925244</link>
      <description>I didn't do a full test of the data. I created some addition data for a test and found a couple bugs in the program.&lt;BR /&gt;&lt;BR /&gt;Find attached the corrected program.&lt;BR /&gt;&lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Tue, 20 Nov 2001 21:45:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sorting-and-formating-script-for-scripting-champions/m-p/2617678#M925244</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2001-11-20T21:45:13Z</dc:date>
    </item>
    <item>
      <title>Re: sorting and formating script - for scripting champions!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sorting-and-formating-script-for-scripting-champions/m-p/2617679#M925245</link>
      <description>Hi Bill,&lt;BR /&gt;&lt;BR /&gt;I don't know what Taps is meant to be, so this may not be correct.  I'd go the perl route, but I know how much you like awk ;-)&lt;BR /&gt;&lt;BR /&gt;Run it with:&lt;BR /&gt;&lt;BR /&gt;awk -F\&amp;gt; -f file.awk file.xml&lt;BR /&gt;&lt;BR /&gt;=========================================&lt;BR /&gt;BEGIN{i=0}&lt;BR /&gt;/&lt;NAME&gt;&lt;/NAME&gt;/&lt;ID&gt;&lt;/ID&gt;/&lt;TYPE&gt;&lt;/TYPE&gt;/&lt;TAPS&gt;&lt;/TAPS&gt;/&amp;lt;\/Drink/{&lt;BR /&gt;bardrink[name" "id]=1&lt;BR /&gt;drinktap[id" "name" "tap]=1&lt;BR /&gt;}&lt;BR /&gt;END{&lt;BR /&gt; for (j=0;j&lt;I&gt;  print "\nBar: "pubs[j]&lt;BR /&gt;  print&lt;BR /&gt;  printf("Drink")&lt;BR /&gt;  for (k=0;k&amp;lt;32;k++)&lt;BR /&gt;   printf(" === i d")&lt;BR /&gt;  printf("\n0-31  ")&lt;BR /&gt;  for (k=0;k&amp;lt;32;k++) {&lt;BR /&gt;   if (bardrink[pubs[j]" "k]==1)&lt;BR /&gt;    printf("--- yes")&lt;BR /&gt;   else&lt;BR /&gt;    printf("--- no ")&lt;BR /&gt;  }&lt;BR /&gt;  printf("\n32-63 ")&lt;BR /&gt;  for (k=32;k&amp;lt;64;k++) {&lt;BR /&gt;   if (bardrink[pubs[j]" "k]==1)&lt;BR /&gt;    printf("--- yes")&lt;BR /&gt;   else&lt;BR /&gt;    printf("--- no ")&lt;BR /&gt;  }&lt;BR /&gt;  print&lt;BR /&gt; }&lt;BR /&gt; for (drink in drinks) {&lt;BR /&gt;  printf("\n\nDrink: %s\n\n",drink)&lt;BR /&gt;  printf("Taps")&lt;BR /&gt;  for (j=0;j&lt;I&gt;   printf(" === %s",pubs[j])&lt;BR /&gt;  for (tap in taps) {&lt;BR /&gt;   printf("\n%d ",tap)&lt;BR /&gt;   for (j=0;j&lt;I&gt;    if (drinktap[drinks[drink]" "pubs[j]" "tap]==1)&lt;BR /&gt;     printf("--- %d",tap)&lt;BR /&gt;    else&lt;BR /&gt;     printf("--- X")&lt;BR /&gt;   }&lt;BR /&gt;  }&lt;BR /&gt; }&lt;BR /&gt; print&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;=========================================&lt;BR /&gt;&lt;BR /&gt;Rgds, Robin&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;</description>
      <pubDate>Wed, 21 Nov 2001 08:54:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sorting-and-formating-script-for-scripting-champions/m-p/2617679#M925245</guid>
      <dc:creator>Robin Wakefield</dc:creator>
      <dc:date>2001-11-21T08:54:22Z</dc:date>
    </item>
  </channel>
</rss>

