<?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: Extract pattern recursively to new file in Operating System - Microsoft</title>
    <link>https://community.hpe.com/t5/operating-system-microsoft/extract-pattern-recursively-to-new-file/m-p/4775381#M9972</link>
    <description>I tried to modify it slightly as below&lt;BR /&gt;startline=`grep -n "transactiion id" myfile.xml | head -1`&lt;BR /&gt;startlineno=`echo ${startline}|cut -d: -f1`&lt;BR /&gt;transname=`echo ${startline}|cut -d"=" -f2|sed -e "1,1s/\"//g"|sed -e "s/&amp;gt;//g"`&lt;BR /&gt;endlineno=`grep -n "/transactiion" myfile.xml | head -1 |cut -d: -f1`&lt;BR /&gt;s2=`expr "${startlineno}"`&lt;BR /&gt;s1=`echo $s2 | awk '{print $1 + 1}'`&lt;BR /&gt;e1=`echo $endlineno | awk '{print $1 - 1}'`&lt;BR /&gt;cat myfile.xml | sed -n ${sl},${el}p &amp;gt; $transname&lt;BR /&gt;&lt;BR /&gt;but it is throwing exception sed: -e expression #1, char 1: unknown command: `,'&lt;BR /&gt;i think its because of the last line cat myfile.xml | sed -n ${sl},${el}p &amp;gt; $transname&lt;BR /&gt;&lt;BR /&gt;I have still not tested it in perl as i am having problems with cygwin setup with perl</description>
    <pubDate>Sat, 09 Apr 2011 11:52:14 GMT</pubDate>
    <dc:creator>Gyan</dc:creator>
    <dc:date>2011-04-09T11:52:14Z</dc:date>
    <item>
      <title>Extract pattern recursively to new file</title>
      <link>https://community.hpe.com/t5/operating-system-microsoft/extract-pattern-recursively-to-new-file/m-p/4775377#M9968</link>
      <description>&lt;TRANSACTIION id="uno"&gt;&lt;BR /&gt; &lt;UNO&gt; Uno punto &lt;/UNO&gt;&lt;BR /&gt; &lt;DOS&gt; Dos punto &lt;/DOS&gt;&lt;BR /&gt; &lt;TRES&gt; transaction &lt;/TRES&gt;&lt;BR /&gt;&lt;/TRANSACTIION&gt;&lt;BR /&gt;&lt;TRANSACTIION id="dos"&gt;&lt;BR /&gt; &lt;UNO&gt;  punto &lt;/UNO&gt;&lt;BR /&gt; &lt;DOS&gt; Dos &lt;/DOS&gt;&lt;BR /&gt; &lt;TRES&gt; transaction &lt;/TRES&gt;&lt;BR /&gt;&lt;/TRANSACTIION&gt;&lt;BR /&gt;&lt;TRANSACTIION id="tres"&gt;&lt;BR /&gt; &lt;UNO&gt; Uno punto &lt;/UNO&gt;&lt;BR /&gt; &lt;DOS&gt; Dos punto &lt;/DOS&gt;&lt;BR /&gt; &lt;TRES&gt; transaction &lt;/TRES&gt;&lt;BR /&gt;&lt;/TRANSACTIION&gt;&lt;BR /&gt;&lt;BR /&gt;I want to extract  each pattern between &lt;TRANSACTIION id="something"&gt; and &lt;/TRANSACTIION&gt; to a new file with the filename as the id of the transactiion element&lt;BR /&gt;&lt;BR /&gt;I want to know how this can be done using awk or sed.Kindly input your thoughts&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Gyan&lt;BR /&gt;</description>
      <pubDate>Fri, 08 Apr 2011 12:35:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-microsoft/extract-pattern-recursively-to-new-file/m-p/4775377#M9968</guid>
      <dc:creator>Gyan</dc:creator>
      <dc:date>2011-04-08T12:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: Extract pattern recursively to new file</title>
      <link>https://community.hpe.com/t5/operating-system-microsoft/extract-pattern-recursively-to-new-file/m-p/4775378#M9969</link>
      <description>I am sure there is a more elaborate way of doing this with perl, but my way uses the quick and dirty shell script (any quasi posix compliant shell, likes of bash, ksh, hpux's sh) way of doing it.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;startline=`grep -n "transaction id" myfile.xml | head -1`&lt;BR /&gt;startlineno=`echo ${startline}|cut -d: -f1`&lt;BR /&gt;transname=`echo ${startline}|cut -d"=" -f2|sed -e "1,1s/\"//g"&lt;BR /&gt;endlineno=`grep -n "/transaction" myfile.xml | head -1 |cut -d: -f1`&lt;BR /&gt;(( sl=${startlineno}+1 ))&lt;BR /&gt;(( el=${endlineno}-1 ))&lt;BR /&gt;cat myfile.xml | sed -n ${sl},${el}p &amp;gt; ${transname}&lt;BR /&gt;cat myfile.xml | sed -e "${startlineno},${endlineno}d" &amp;gt; tmpxmlfile&lt;BR /&gt;cat tmpxmlfile &amp;gt; myfile.xml&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;at this point, you have extracted the first xml block out of the file and placed in the transaction named file and deleted the extracted portion from the original file.&lt;BR /&gt;&lt;BR /&gt;Now, for the rest of your homework studies, you need to build a while/do construct to go through the file until there is nothing left in it. It is only fair if you do part of the homework yourself :) Isn't it ?&lt;BR /&gt;</description>
      <pubDate>Fri, 08 Apr 2011 13:45:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-microsoft/extract-pattern-recursively-to-new-file/m-p/4775378#M9969</guid>
      <dc:creator>Mel Burslan</dc:creator>
      <dc:date>2011-04-08T13:45:00Z</dc:date>
    </item>
    <item>
      <title>Re: Extract pattern recursively to new file</title>
      <link>https://community.hpe.com/t5/operating-system-microsoft/extract-pattern-recursively-to-new-file/m-p/4775379#M9970</link>
      <description>&lt;BR /&gt;There is probably some XML tool to do this for you. &lt;BR /&gt;&lt;BR /&gt;But if it is for a one-off, controlled, situation then yo may try for example a quick PERL solution :&lt;BR /&gt;&lt;BR /&gt;# perl -ne 'close F if m~^$1.tmp") if /^&lt;TRA.&gt;&lt;/TRA.&gt;&lt;BR /&gt;explanation&lt;BR /&gt;&lt;BR /&gt;# perl -ne  ' ## start perl looping over input&lt;BR /&gt;close F if m~^print F if F; ## Print any line while file handle defined.&lt;BR /&gt;open (F,"&amp;gt;$1.tmp") ## Open a file F for output with name from variable $1&lt;BR /&gt;if /^&lt;TRA.&gt;&lt;/TRA.&gt;&lt;BR /&gt;&lt;BR /&gt;Full example below.&lt;BR /&gt;hth,&lt;BR /&gt;Hein&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;# ls *.tmp&lt;BR /&gt;x.tmp&lt;BR /&gt;# perl -ne 'close F if m~^$1.tmp") if /^&lt;TRA.&gt;&lt;/TRA.&gt;# ls -l *.tmp&lt;BR /&gt;-rw-r--r-- 1 Administrator None  70 Apr  8 10:34 dos.tmp&lt;BR /&gt;-rw-r--r-- 1 Administrator None  80 Apr  8 10:34 tres.tmp&lt;BR /&gt;-rw-r--r-- 1 Administrator None  80 Apr  8 10:34 uno.tmp&lt;BR /&gt;-rw-r--r-- 1 Administrator None 355 Apr  8 10:34 x.tmp&lt;BR /&gt;# cat dos.tmp&lt;BR /&gt;&lt;UNO&gt; 2 punto &lt;/UNO&gt;&lt;BR /&gt;&lt;DOS&gt; 2 Dos &lt;/DOS&gt;&lt;BR /&gt;&lt;TRES&gt; transaction &lt;/TRES&gt;&lt;BR /&gt;#&lt;BR /&gt;# cat x.tmp&lt;BR /&gt;&lt;TRANSACTIION id="uno"&gt;&lt;BR /&gt;&lt;UNO&gt; 1 Uno punto &lt;/UNO&gt;&lt;BR /&gt;&lt;DOS&gt; 1 Dos punto &lt;/DOS&gt;&lt;BR /&gt;&lt;TRES&gt; transaction &lt;/TRES&gt;&lt;BR /&gt;&lt;/TRANSACTIION&gt;&lt;BR /&gt;&lt;TRANSACTIION id="dos"&gt;&lt;BR /&gt;&lt;UNO&gt; 2 punto &lt;/UNO&gt;&lt;BR /&gt;&lt;DOS&gt; 2 Dos &lt;/DOS&gt;&lt;BR /&gt;&lt;TRES&gt; transaction &lt;/TRES&gt;&lt;BR /&gt;&lt;/TRANSACTIION&gt;&lt;BR /&gt;&lt;TRANSACTIION id="tres"&gt;&lt;BR /&gt;&lt;UNO&gt; 3 Uno punto &lt;/UNO&gt;&lt;BR /&gt;&lt;DOS&gt; 3 Dos punto &lt;/DOS&gt;&lt;BR /&gt;&lt;TRES&gt; transaction &lt;/TRES&gt;&lt;BR /&gt;&lt;/TRANSACTIION&gt;#&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 08 Apr 2011 13:50:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-microsoft/extract-pattern-recursively-to-new-file/m-p/4775379#M9970</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2011-04-08T13:50:40Z</dc:date>
    </item>
    <item>
      <title>Re: Extract pattern recursively to new file</title>
      <link>https://community.hpe.com/t5/operating-system-microsoft/extract-pattern-recursively-to-new-file/m-p/4775380#M9971</link>
      <description>Forgot one line explanation detail&lt;BR /&gt;&lt;BR /&gt;if /^&lt;TRA.&gt;&lt;/TRA.&gt;&lt;BR /&gt;Broken down&lt;BR /&gt;&lt;BR /&gt;^    ## at begin of line&lt;BR /&gt;&lt;TRA.&gt;&lt;/TRA.&gt;(.+)"/   ## remember anything up to the closing " in variable $1&lt;BR /&gt;' x.tmp ## close the program text, and specify input.&lt;BR /&gt;&lt;BR /&gt;You surely noticed how I changed you input file example to be able to distiguish lines by id.&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Fri, 08 Apr 2011 14:10:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-microsoft/extract-pattern-recursively-to-new-file/m-p/4775380#M9971</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2011-04-08T14:10:19Z</dc:date>
    </item>
    <item>
      <title>Re: Extract pattern recursively to new file</title>
      <link>https://community.hpe.com/t5/operating-system-microsoft/extract-pattern-recursively-to-new-file/m-p/4775381#M9972</link>
      <description>I tried to modify it slightly as below&lt;BR /&gt;startline=`grep -n "transactiion id" myfile.xml | head -1`&lt;BR /&gt;startlineno=`echo ${startline}|cut -d: -f1`&lt;BR /&gt;transname=`echo ${startline}|cut -d"=" -f2|sed -e "1,1s/\"//g"|sed -e "s/&amp;gt;//g"`&lt;BR /&gt;endlineno=`grep -n "/transactiion" myfile.xml | head -1 |cut -d: -f1`&lt;BR /&gt;s2=`expr "${startlineno}"`&lt;BR /&gt;s1=`echo $s2 | awk '{print $1 + 1}'`&lt;BR /&gt;e1=`echo $endlineno | awk '{print $1 - 1}'`&lt;BR /&gt;cat myfile.xml | sed -n ${sl},${el}p &amp;gt; $transname&lt;BR /&gt;&lt;BR /&gt;but it is throwing exception sed: -e expression #1, char 1: unknown command: `,'&lt;BR /&gt;i think its because of the last line cat myfile.xml | sed -n ${sl},${el}p &amp;gt; $transname&lt;BR /&gt;&lt;BR /&gt;I have still not tested it in perl as i am having problems with cygwin setup with perl</description>
      <pubDate>Sat, 09 Apr 2011 11:52:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-microsoft/extract-pattern-recursively-to-new-file/m-p/4775381#M9972</guid>
      <dc:creator>Gyan</dc:creator>
      <dc:date>2011-04-09T11:52:14Z</dc:date>
    </item>
    <item>
      <title>Re: Extract pattern recursively to new file</title>
      <link>https://community.hpe.com/t5/operating-system-microsoft/extract-pattern-recursively-to-new-file/m-p/4775382#M9973</link>
      <description>&lt;BR /&gt;&amp;gt;&amp;gt; not tested it in perl as i am having problems with cygwin setup with perl&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;fwiw... I tested my answer under cygwin.&lt;BR /&gt;&lt;BR /&gt;Hein&lt;BR /&gt;</description>
      <pubDate>Sat, 09 Apr 2011 11:59:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-microsoft/extract-pattern-recursively-to-new-file/m-p/4775382#M9973</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2011-04-09T11:59:34Z</dc:date>
    </item>
    <item>
      <title>Re: Extract pattern recursively to new file</title>
      <link>https://community.hpe.com/t5/operating-system-microsoft/extract-pattern-recursively-to-new-file/m-p/4775383#M9974</link>
      <description>AS my environment is supporting only bash scripting thats why i wrote in my initial mail&lt;BR /&gt;&lt;BR /&gt;"I want to know how this can be done using awk or sed."&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 09 Apr 2011 12:17:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-microsoft/extract-pattern-recursively-to-new-file/m-p/4775383#M9974</guid>
      <dc:creator>Gyan</dc:creator>
      <dc:date>2011-04-09T12:17:39Z</dc:date>
    </item>
    <item>
      <title>Re: Extract pattern recursively to new file</title>
      <link>https://community.hpe.com/t5/operating-system-microsoft/extract-pattern-recursively-to-new-file/m-p/4775384#M9975</link>
      <description>&lt;BR /&gt;contemplation:&lt;BR /&gt;&lt;BR /&gt;Hmmm,  you were entering your question in an HPUX forum. That suggests that PERL is available as just an other tool.&lt;BR /&gt;&lt;BR /&gt;You really want to get perl in your toolbox... it is handy.&lt;BR /&gt;&lt;BR /&gt;condemnation:&lt;BR /&gt;&lt;BR /&gt;Anyway, the same perl method maps easily onto AWK:&lt;BR /&gt;&lt;BR /&gt;awk '/^&amp;lt;\/tra/ {F=""} F {print $0&amp;gt;F}  /^&lt;TRA&gt;&lt;/TRA&gt;&lt;BR /&gt;explanation:&lt;BR /&gt;&lt;BR /&gt;/^&amp;lt;\/tra/ {F=""}   ## mark file as close at end of transaction&lt;BR /&gt;F {print $0&amp;gt;F}  ## IF there is a filename then print on that file.&lt;BR /&gt;&lt;BR /&gt;/^&lt;TRA&gt;&lt;/TRA&gt;F=a[2] ".tmp" }  ## compose output file name from split array&lt;BR /&gt;&lt;BR /&gt;demonstration:&lt;BR /&gt;&lt;BR /&gt;# cp x.txt x.tmp&lt;BR /&gt;# dir *.tmp&lt;BR /&gt;x.tmp&lt;BR /&gt;# awk '/^&amp;lt;\/tra/ {F=""} F {print $0&amp;gt;F}  /^&lt;TRA&gt;&lt;/TRA&gt;# dir *.tmp&lt;BR /&gt;dos.tmp  tres.tmp  uno.tmp  x.tmp&lt;BR /&gt;# cat dos.tmp&lt;BR /&gt;&lt;UNO&gt; 2 punto &lt;/UNO&gt;&lt;BR /&gt;&lt;DOS&gt; 2 Dos &lt;/DOS&gt;&lt;BR /&gt;&lt;TRES&gt; transaction &lt;/TRES&gt;&lt;BR /&gt;# cat x.tmp&lt;BR /&gt;&lt;TRANSACTIION id="uno"&gt;&lt;BR /&gt;&lt;UNO&gt; 1 Uno punto &lt;/UNO&gt;&lt;BR /&gt;&lt;DOS&gt; 1 Dos punto &lt;/DOS&gt;&lt;BR /&gt;&lt;TRES&gt; transaction &lt;/TRES&gt;&lt;BR /&gt;&lt;/TRANSACTIION&gt;&lt;BR /&gt;&lt;TRANSACTIION id="dos"&gt;&lt;BR /&gt;&lt;UNO&gt; 2 punto &lt;/UNO&gt;&lt;BR /&gt;&lt;DOS&gt; 2 Dos &lt;/DOS&gt;&lt;BR /&gt;&lt;TRES&gt; transaction &lt;/TRES&gt;&lt;BR /&gt;&lt;/TRANSACTIION&gt;&lt;BR /&gt;&lt;TRANSACTIION id="tres"&gt;&lt;BR /&gt;&lt;UNO&gt; 3 Uno punto &lt;/UNO&gt;&lt;BR /&gt;&lt;DOS&gt; 3 Dos punto &lt;/DOS&gt;&lt;BR /&gt;&lt;TRES&gt; transaction &lt;/TRES&gt;&lt;BR /&gt;&lt;/TRANSACTIION&gt;&lt;BR /&gt;#&lt;BR /&gt;&lt;BR /&gt;salutation:&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Sat, 09 Apr 2011 13:33:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-microsoft/extract-pattern-recursively-to-new-file/m-p/4775384#M9975</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2011-04-09T13:33:32Z</dc:date>
    </item>
    <item>
      <title>Re: Extract pattern recursively to new file</title>
      <link>https://community.hpe.com/t5/operating-system-microsoft/extract-pattern-recursively-to-new-file/m-p/4775385#M9976</link>
      <description>Well, the solution I provided, works pretty fine including sed and all else on HPUX /bin/sh shell. cygwin or any windows emulation of unix shell is subject to their particular interpretation and implementation of these tools and compatibility between the two is not always guaranteed.&lt;BR /&gt;&lt;BR /&gt;I am sure there are countless number of cygwin related forims, albeit not as active as this one and if you answer your question in one of those, sooner or later, you will get a response.</description>
      <pubDate>Sun, 10 Apr 2011 00:26:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-microsoft/extract-pattern-recursively-to-new-file/m-p/4775385#M9976</guid>
      <dc:creator>Mel Burslan</dc:creator>
      <dc:date>2011-04-10T00:26:46Z</dc:date>
    </item>
    <item>
      <title>Re: Extract pattern recursively to new file</title>
      <link>https://community.hpe.com/t5/operating-system-microsoft/extract-pattern-recursively-to-new-file/m-p/4775386#M9977</link>
      <description>The awk stuff works, maybe i need to purchase a copy of hp-ux to get things moving :) Thanks everybody</description>
      <pubDate>Sun, 10 Apr 2011 02:19:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-microsoft/extract-pattern-recursively-to-new-file/m-p/4775386#M9977</guid>
      <dc:creator>Gyan</dc:creator>
      <dc:date>2011-04-10T02:19:37Z</dc:date>
    </item>
  </channel>
</rss>

