<?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: xml search/parse script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/xml-search-parse-script/m-p/2579498#M920719</link>
    <description>Hi Bill,&lt;BR /&gt;&lt;BR /&gt;And no, that wasn't a deliberately-forget-something-to-get-more-points reply, but thanks anyway!!&lt;BR /&gt;&lt;BR /&gt;Rgds, Robin.</description>
    <pubDate>Fri, 14 Sep 2001 11:16:24 GMT</pubDate>
    <dc:creator>Robin Wakefield</dc:creator>
    <dc:date>2001-09-14T11:16:24Z</dc:date>
    <item>
      <title>xml search/parse script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/xml-search-parse-script/m-p/2579494#M920715</link>
      <description>Hi, I'm trying to create a script to analyse an xml file in the following format.&lt;BR /&gt;&lt;BR /&gt;&lt;SHOP&gt;&lt;BR /&gt; &lt;NAME&gt;BeerStore&lt;/NAME&gt;&lt;BR /&gt; &lt;ADDRESS&gt;1 street&lt;/ADDRESS&gt;&lt;BR /&gt; &lt;DRINK&gt;&lt;BR /&gt;   &lt;BRAND&gt;&lt;BR /&gt;    &lt;NAME&gt;Guinness&lt;/NAME&gt;&lt;BR /&gt;    &lt;TYPE&gt;Stout&lt;/TYPE&gt;&lt;BR /&gt;    &lt;HOWMANY&gt;6&lt;/HOWMANY&gt;&lt;BR /&gt;   &lt;/BRAND&gt;&lt;BR /&gt;   &lt;BRAND&gt;&lt;BR /&gt;    &lt;NAME&gt;Budweiser&lt;/NAME&gt;&lt;BR /&gt;    &lt;TYPE&gt;Larger&lt;/TYPE&gt;&lt;BR /&gt;    &lt;HOWMANY&gt;6&lt;/HOWMANY&gt;&lt;BR /&gt;   &lt;/BRAND&gt;&lt;BR /&gt; &lt;/DRINK&gt;&lt;BR /&gt;&lt;/SHOP&gt;&lt;BR /&gt;&lt;SHOP&gt;&lt;BR /&gt; &lt;NAME&gt;SpiritStore&lt;/NAME&gt;&lt;BR /&gt; &lt;ADDRESS&gt;2 street&lt;/ADDRESS&gt;&lt;BR /&gt; &lt;DRINK&gt;&lt;BR /&gt;   &lt;BRAND&gt;&lt;BR /&gt;    &lt;NAME&gt;Baileys&lt;/NAME&gt;&lt;BR /&gt;    &lt;TYPE&gt;Cream from the center of the Earth&lt;/TYPE&gt;&lt;BR /&gt;    &lt;HOWMANY&gt;2&lt;/HOWMANY&gt;&lt;BR /&gt;   &lt;/BRAND&gt;&lt;BR /&gt;   &lt;BRAND&gt;&lt;BR /&gt;    &lt;NAME&gt;Paddy&lt;/NAME&gt;&lt;BR /&gt;    &lt;TYPE&gt;Whiskey&lt;/TYPE&gt;&lt;BR /&gt;    &lt;HOWMANY&gt;2&lt;/HOWMANY&gt;&lt;BR /&gt;   &lt;/BRAND&gt;&lt;BR /&gt; &lt;/DRINK&gt;&lt;BR /&gt;&lt;/SHOP&gt;&lt;BR /&gt;&lt;BR /&gt;Now I'd like to do a search on&lt;BR /&gt;Say 'Paddy' and find out 'HowMany' are due and in which 'Shop' to order through script.&lt;BR /&gt;&lt;BR /&gt;Something like this:&lt;BR /&gt;#./script Paddy&lt;BR /&gt;You get Paddy in SpiritStore, 2 street and you need 2&lt;BR /&gt;Have a great day!!&lt;BR /&gt;#&lt;BR /&gt;&lt;BR /&gt;Any ideas on how to proceed!?&lt;BR /&gt;All suggestions welcome/rewarded!&lt;BR /&gt;&lt;BR /&gt;Later,&lt;BR /&gt;Bill</description>
      <pubDate>Fri, 14 Sep 2001 09:09:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/xml-search-parse-script/m-p/2579494#M920715</guid>
      <dc:creator>Bill McNAMARA_1</dc:creator>
      <dc:date>2001-09-14T09:09:22Z</dc:date>
    </item>
    <item>
      <title>Re: xml search/parse script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/xml-search-parse-script/m-p/2579495#M920716</link>
      <description>Hi Bill&lt;BR /&gt;&lt;BR /&gt;create awk script as follows:&lt;BR /&gt;================================&lt;BR /&gt;$0 ~ search{GOTIT=1}&lt;BR /&gt;/&lt;NAME&gt;/{NAME=substr($0,7,length($0)-14)}&lt;BR /&gt;/&lt;ADDRESS&gt;/{GOTNAME=NAME;ADDRESS=substr($0,10,length($0)-20)}&lt;BR /&gt;/&lt;HOWMANY&gt;/{HOWMANY=substr($0,10,length($0)-20)&lt;BR /&gt;if (GOTIT == 1) {print "You get",NAME,"in",ADDRESS,"and you need",HOWMANY};GOTIT=0}&lt;BR /&gt;&lt;BR /&gt;==============================&lt;BR /&gt;&lt;BR /&gt;and run it with:&lt;BR /&gt;&lt;BR /&gt;awk -f above-script search=Paddy inputfile&lt;BR /&gt;&lt;BR /&gt;Rgds, Robin&lt;/HOWMANY&gt;&lt;/ADDRESS&gt;&lt;/NAME&gt;</description>
      <pubDate>Fri, 14 Sep 2001 10:05:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/xml-search-parse-script/m-p/2579495#M920716</guid>
      <dc:creator>Robin Wakefield</dc:creator>
      <dc:date>2001-09-14T10:05:59Z</dc:date>
    </item>
    <item>
      <title>Re: xml search/parse script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/xml-search-parse-script/m-p/2579496#M920717</link>
      <description>Hi Bill,&lt;BR /&gt;&lt;BR /&gt;Sorry, the last line should read:&lt;BR /&gt;&lt;BR /&gt;if (GOTIT == 1) {print "You get",NAME,"in",GOTNAME",",ADDRESS,"and you need",HOWMANY};GOTIT=0}&lt;BR /&gt;&lt;BR /&gt;Rgds, Robin</description>
      <pubDate>Fri, 14 Sep 2001 10:17:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/xml-search-parse-script/m-p/2579496#M920717</guid>
      <dc:creator>Robin Wakefield</dc:creator>
      <dc:date>2001-09-14T10:17:57Z</dc:date>
    </item>
    <item>
      <title>Re: xml search/parse script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/xml-search-parse-script/m-p/2579497#M920718</link>
      <description>I have absolutely no idea how it works, but it does!!&lt;BR /&gt;&lt;BR /&gt;Thanks Robin.&lt;BR /&gt;Bill</description>
      <pubDate>Fri, 14 Sep 2001 11:09:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/xml-search-parse-script/m-p/2579497#M920718</guid>
      <dc:creator>Bill McNAMARA_1</dc:creator>
      <dc:date>2001-09-14T11:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: xml search/parse script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/xml-search-parse-script/m-p/2579498#M920719</link>
      <description>Hi Bill,&lt;BR /&gt;&lt;BR /&gt;And no, that wasn't a deliberately-forget-something-to-get-more-points reply, but thanks anyway!!&lt;BR /&gt;&lt;BR /&gt;Rgds, Robin.</description>
      <pubDate>Fri, 14 Sep 2001 11:16:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/xml-search-parse-script/m-p/2579498#M920719</guid>
      <dc:creator>Robin Wakefield</dc:creator>
      <dc:date>2001-09-14T11:16:24Z</dc:date>
    </item>
    <item>
      <title>Re: xml search/parse script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/xml-search-parse-script/m-p/2579499#M920720</link>
      <description>Apologies Robin, my knowledge of awk is limited to print..&lt;BR /&gt;I need your help a bit more!&lt;BR /&gt;&lt;BR /&gt;I changed the text to match my xml files and am getting some problems..&lt;BR /&gt;This is the real text:&lt;BR /&gt;&lt;BR /&gt;The o/p should be &lt;BR /&gt;A search for lets say &lt;VALUE&gt; 543&lt;BR /&gt; &lt;BR /&gt;returning within &lt;TRUNKGROUP&gt;&lt;BR /&gt;data_00_33 &lt;MAPPING&gt;whatever..&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;---------------------&lt;BR /&gt;- &lt;TRUNKGROUP&gt;&lt;BR /&gt;  &lt;NAME&gt;data_00_33&lt;/NAME&gt; &lt;BR /&gt;  &lt;BARECHANNEL&gt;E1&lt;/BARECHANNEL&gt; &lt;BR /&gt;  &lt;TYPE&gt;ISUP&lt;/TYPE&gt; &lt;BR /&gt;  &lt;DPC&gt;10&lt;/DPC&gt; &lt;BR /&gt;  &lt;TRANSPORTMAPPING&gt;rio.0.0.33&lt;/TRANSPORTMAPPING&gt; &lt;BR /&gt;+ &lt;CHANNELMAPPING&gt;&lt;BR /&gt;  &lt;ID&gt;31&lt;/ID&gt; &lt;BR /&gt;  &lt;MAPPING&gt;CIC-NO&lt;/MAPPING&gt; &lt;BR /&gt;  &lt;CHANNELDPC&gt;10&lt;/CHANNELDPC&gt; &lt;BR /&gt;  &lt;VALUE&gt;543&lt;/VALUE&gt; &lt;BR /&gt;  &lt;/CHANNELMAPPING&gt;&lt;BR /&gt;+ &lt;CHANNELMAPPING&gt;&lt;BR /&gt;  &lt;ID&gt;30&lt;/ID&gt; &lt;BR /&gt;  &lt;MAPPING&gt;CIC-NO&lt;/MAPPING&gt; &lt;BR /&gt;  &lt;CHANNELDPC&gt;10&lt;/CHANNELDPC&gt; &lt;BR /&gt;  &lt;VALUE&gt;542&lt;/VALUE&gt; &lt;BR /&gt;  &lt;/CHANNELMAPPING&gt;&lt;BR /&gt;+ &lt;CHANNELMAPPING&gt;&lt;BR /&gt;  &lt;ID&gt;29&lt;/ID&gt; &lt;BR /&gt;  &lt;MAPPING&gt;CIC-NO&lt;/MAPPING&gt; &lt;BR /&gt;  &lt;CHANNELDPC&gt;10&lt;/CHANNELDPC&gt; &lt;BR /&gt;  &lt;VALUE&gt;541&lt;/VALUE&gt; &lt;BR /&gt;  &lt;/CHANNELMAPPING&gt;&lt;BR /&gt; &lt;CHANNELMAPPING&gt;&lt;BR /&gt;  &lt;ID&gt;28&lt;/ID&gt; &lt;BR /&gt;  &lt;MAPPING&gt;CIC-NO&lt;/MAPPING&gt; &lt;BR /&gt;  &lt;CHANNELDPC&gt;10&lt;/CHANNELDPC&gt; &lt;BR /&gt;  &lt;VALUE&gt;540&lt;/VALUE&gt; &lt;BR /&gt;  &lt;/CHANNELMAPPING&gt;&lt;BR /&gt; &lt;CHANNELMAPPING&gt;&lt;BR /&gt;  &lt;ID&gt;27&lt;/ID&gt; &lt;BR /&gt;  &lt;MAPPING&gt;CIC-NO&lt;/MAPPING&gt; &lt;BR /&gt;  &lt;CHANNELDPC&gt;10&lt;/CHANNELDPC&gt; &lt;BR /&gt;  &lt;VALUE&gt;539&lt;/VALUE&gt; &lt;BR /&gt;  &lt;/CHANNELMAPPING&gt;&lt;BR /&gt; &lt;CHANNELMAPPING&gt;&lt;BR /&gt;  &lt;ID&gt;26&lt;/ID&gt; &lt;BR /&gt;  &lt;MAPPING&gt;CIC-NO&lt;/MAPPING&gt; &lt;BR /&gt;  &lt;CHANNELDPC&gt;10&lt;/CHANNELDPC&gt; &lt;BR /&gt;  &lt;VALUE&gt;538&lt;/VALUE&gt; &lt;BR /&gt;  &lt;/CHANNELMAPPING&gt;&lt;BR /&gt; &lt;CHANNELMAPPING&gt;&lt;BR /&gt;  &lt;ID&gt;25&lt;/ID&gt; &lt;BR /&gt;  &lt;MAPPING&gt;CIC-NO&lt;/MAPPING&gt; &lt;BR /&gt;  &lt;CHANNELDPC&gt;10&lt;/CHANNELDPC&gt; &lt;BR /&gt;  &lt;VALUE&gt;537&lt;/VALUE&gt; &lt;BR /&gt;  &lt;/CHANNELMAPPING&gt;&lt;BR /&gt;&lt;/TRUNKGROUP&gt;&lt;/MAPPING&gt;&lt;/TRUNKGROUP&gt;&lt;/VALUE&gt;</description>
      <pubDate>Fri, 14 Sep 2001 11:58:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/xml-search-parse-script/m-p/2579499#M920720</guid>
      <dc:creator>Bill McNAMARA_1</dc:creator>
      <dc:date>2001-09-14T11:58:57Z</dc:date>
    </item>
    <item>
      <title>Re: xml search/parse script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/xml-search-parse-script/m-p/2579500#M920721</link>
      <description># awk -f /tmp/script.awk search=7 /tmp/Conf_Pereal.xm&amp;gt;&lt;BR /&gt;You get  in ,  and you need  &lt;TRANSPORTMAPPING&gt;p&lt;BR /&gt;You get        in       ,  and you need  &lt;TRANSPORTMAPPING&gt;p&lt;BR /&gt;&lt;BR /&gt;awk script:&lt;BR /&gt;$0 ~ search{GOTIT=1}&lt;BR /&gt;/&lt;VALUE&gt;/{VALUE=substr($0,7,length($0)-14)}&lt;BR /&gt;/&lt;TRUNKGROUP&gt;/{GOTNAME=VALUE;TRUNKGROUP=substr($0,10,length($0)-20)}&lt;BR /&gt;/&lt;TRANSPORTMAPPING&gt;/{TRANSPORTMAPPING=substr($0,10,length($0)-20)&lt;BR /&gt;if (GOTIT == 1) {print "You get",VALUE,"in",GOTNAME",",TRUNKGROUP,"and you need"&lt;BR /&gt;,TRANSPORTMAPPING};GOTIT=0}&lt;BR /&gt;&lt;BR /&gt;xml attached&lt;BR /&gt;&lt;/TRANSPORTMAPPING&gt;&lt;/TRUNKGROUP&gt;&lt;/VALUE&gt;&lt;/TRANSPORTMAPPING&gt;&lt;/TRANSPORTMAPPING&gt;</description>
      <pubDate>Fri, 14 Sep 2001 12:22:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/xml-search-parse-script/m-p/2579500#M920721</guid>
      <dc:creator>Bill McNAMARA_1</dc:creator>
      <dc:date>2001-09-14T12:22:30Z</dc:date>
    </item>
    <item>
      <title>Re: xml search/parse script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/xml-search-parse-script/m-p/2579501#M920722</link>
      <description>Hi Bill,&lt;BR /&gt;&lt;BR /&gt;Try this:&lt;BR /&gt;&lt;BR /&gt;=============================&lt;BR /&gt;$0 ~ "&lt;VALUE&gt;" search{GOTIT=1}&lt;BR /&gt;{sub(/^  */,"",$0)}&lt;BR /&gt;/&lt;NAME&gt;/{TRUNKGROUP=substr($0,7)}&lt;BR /&gt;/&lt;TRANSPORTMAPPING&gt;/{TRANSPORTMAPPING=substr($0,19) }&lt;BR /&gt;/&lt;VALUE&gt;/{VALUE=substr($0,8)&lt;BR /&gt;if (GOTIT == 1) {print "You get",VALUE,"in Trunkgroup",&lt;BR /&gt;TRUNKGROUP,"and you need Mapping",TRANSPORTMAPPING};GOTIT=0}&lt;BR /&gt;&lt;BR /&gt;=============================&lt;BR /&gt;&lt;BR /&gt;The file you attached was slightly different to the initial format in that, for instance &lt;/VALUE&gt; was on a line of its own.  I have assumed &lt;NAME&gt; only ever refers to a Trunkgroup.&lt;BR /&gt;&lt;BR /&gt;If you want to play with the script, the figure in the substr function is the length of the search string + 1, e.g. &lt;NAME&gt; is 6 chars + 1 =7.&lt;BR /&gt;&lt;BR /&gt;The sub at the beginning removes leading spaces.  I also assume you only want to search on the &lt;VALUE&gt; parameter.&lt;BR /&gt;&lt;BR /&gt;Anyway, give it a go, let me know of any problems.&lt;BR /&gt;&lt;BR /&gt;Rgds, Robin.&lt;/VALUE&gt;&lt;/NAME&gt;&lt;/NAME&gt;&lt;/TRANSPORTMAPPING&gt;&lt;/NAME&gt;&lt;/VALUE&gt;</description>
      <pubDate>Fri, 14 Sep 2001 13:37:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/xml-search-parse-script/m-p/2579501#M920722</guid>
      <dc:creator>Robin Wakefield</dc:creator>
      <dc:date>2001-09-14T13:37:23Z</dc:date>
    </item>
    <item>
      <title>Re: xml search/parse script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/xml-search-parse-script/m-p/2579502#M920723</link>
      <description>Thanks!.. I'm going to have to learn awk..&lt;BR /&gt;&lt;BR /&gt;In anycase, The o/p is something like the following now, which is perfectly correct... but just for cosmetic reasons, how could I get rid of the  and others.. without limiting the fields to character lengths..&lt;BR /&gt;&lt;BR /&gt;CIC: 12345678 found&lt;BR /&gt;Trunkgroup: TG_00_00&lt;BR /&gt;Transport Mapping: pereal.0.0.0&lt;BR /&gt;Thanks again,&lt;BR /&gt;Bill</description>
      <pubDate>Fri, 14 Sep 2001 13:59:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/xml-search-parse-script/m-p/2579502#M920723</guid>
      <dc:creator>Bill McNAMARA_1</dc:creator>
      <dc:date>2001-09-14T13:59:48Z</dc:date>
    </item>
    <item>
      <title>Re: xml search/parse script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/xml-search-parse-script/m-p/2579503#M920724</link>
      <description>Hi Bill,&lt;BR /&gt;&lt;BR /&gt;OK, sounds like I was working on a slightly different file format, but it's easy enough to remove the trailing strings.&lt;BR /&gt;&lt;BR /&gt;If you have a look back to my original script, I have a third argument to the substr function - this tells awk to only output a string of this length.  This will equal the length of the original line, length($0), minus the length of, say, &lt;VALUE&gt; + &lt;/VALUE&gt;.  You may need to adjust this figure if you have trailing spaces, as I did.&lt;BR /&gt;&lt;BR /&gt;Got to dash now, but hopefully that will help.&lt;BR /&gt;&lt;BR /&gt;Rgds, Robin</description>
      <pubDate>Fri, 14 Sep 2001 14:20:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/xml-search-parse-script/m-p/2579503#M920724</guid>
      <dc:creator>Robin Wakefield</dc:creator>
      <dc:date>2001-09-14T14:20:07Z</dc:date>
    </item>
    <item>
      <title>Re: xml search/parse script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/xml-search-parse-script/m-p/2579504#M920725</link>
      <description>have a good weekend Robin,&lt;BR /&gt;Thanks for the help.&lt;BR /&gt;&lt;BR /&gt;Bill</description>
      <pubDate>Fri, 14 Sep 2001 14:21:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/xml-search-parse-script/m-p/2579504#M920725</guid>
      <dc:creator>Bill McNAMARA_1</dc:creator>
      <dc:date>2001-09-14T14:21:39Z</dc:date>
    </item>
  </channel>
</rss>

