<?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: pattern match in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/pattern-match/m-p/3391116#M199152</link>
    <description>Hi Rahul,&lt;BR /&gt;&lt;BR /&gt;Not a great script. As long as the ID stuff looks like &lt;ID&gt;&lt;SOMENUMBER&gt;&lt;/SOMENUMBER&gt;, then it will work. If you have some junk in place of &lt;SOMENUMBER&gt;, then you will see junk files getting created. So, try it in a test directory. May someone come up with a nicer one.&lt;BR /&gt;&lt;BR /&gt;grep "&lt;ID&gt;" data|sort |uniq|while read i&lt;BR /&gt;do&lt;BR /&gt;FILE=$(echo "$i" |sed -e 's/&amp;gt;//g' -e 's/echo $FILE&lt;BR /&gt;sed -n -e '/&lt;ID&gt;'$FILE'&amp;lt;\/ID&amp;gt;/,/&lt;ID&gt;/p' data |sed  -e '/&lt;ID&gt;*/d'  &amp;gt;&amp;gt; $FILE.out&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;-Sri&lt;/ID&gt;&lt;/ID&gt;&lt;/ID&gt;&lt;/ID&gt;&lt;/SOMENUMBER&gt;&lt;/ID&gt;</description>
    <pubDate>Thu, 30 Sep 2004 19:25:52 GMT</pubDate>
    <dc:creator>Sridhar Bhaskarla</dc:creator>
    <dc:date>2004-09-30T19:25:52Z</dc:date>
    <item>
      <title>pattern match</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pattern-match/m-p/3391113#M199149</link>
      <description>Hi ,&lt;BR /&gt;&lt;BR /&gt;I have a file like:&lt;BR /&gt;&lt;BR /&gt;&lt;ID&gt;1&lt;/ID&gt;&lt;BR /&gt;abc&lt;BR /&gt;def&lt;BR /&gt;ghi&lt;BR /&gt;&lt;ID&gt;2&lt;/ID&gt;&lt;BR /&gt;dhkhfk&lt;BR /&gt;hdfklhfl&lt;BR /&gt;hflhflf&lt;BR /&gt;&lt;ID&gt;1&lt;/ID&gt;&lt;BR /&gt;nlltln&lt;BR /&gt;hlorn;f&lt;BR /&gt;nlahflh&lt;BR /&gt;&lt;ID&gt;3&lt;/ID&gt;&lt;BR /&gt;b,xbx&lt;BR /&gt;nn.vn&lt;BR /&gt;nflhfl&lt;BR /&gt;&lt;ID&gt;4&lt;/ID&gt;&lt;BR /&gt;ahff&lt;BR /&gt;jhflk&lt;BR /&gt;&lt;BR /&gt;I need to grep for all the occurances for&lt;ID&gt;1&lt;/ID&gt; and print the lines that follows after it in a seprate file. Similiarly I have to do it for &lt;ID&gt;2&lt;/ID&gt;, &lt;ID&gt;3&lt;/ID&gt;, &lt;ID&gt;4&lt;/ID&gt;. &lt;BR /&gt;&lt;BR /&gt;Can anyone please help me to do this.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Rahul</description>
      <pubDate>Thu, 30 Sep 2004 17:28:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pattern-match/m-p/3391113#M199149</guid>
      <dc:creator>Rahul_13</dc:creator>
      <dc:date>2004-09-30T17:28:33Z</dc:date>
    </item>
    <item>
      <title>Re: pattern match</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pattern-match/m-p/3391114#M199150</link>
      <description>Hello Rahul,&lt;BR /&gt;&lt;BR /&gt;If each time the &lt;ID&gt;x&lt;/ID&gt; sequence is followed by 3 lines, you may get a solution by using a small awk script combined with 'getline' which will force the read of next line each time.&lt;BR /&gt;&lt;BR /&gt;Hope this helps,  Bye.&lt;BR /&gt;&lt;BR /&gt;Francis.</description>
      <pubDate>Thu, 30 Sep 2004 18:15:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pattern-match/m-p/3391114#M199150</guid>
      <dc:creator>Francis_12</dc:creator>
      <dc:date>2004-09-30T18:15:07Z</dc:date>
    </item>
    <item>
      <title>Re: pattern match</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pattern-match/m-p/3391115#M199151</link>
      <description>Hi Francis,&lt;BR /&gt;&lt;BR /&gt;The number of line after &lt;ID&gt;x&lt;/ID&gt; is not 3 but it is some "x" number which is fixed. &lt;BR /&gt;&lt;BR /&gt;Can you please let me know how to do it.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Rahul</description>
      <pubDate>Thu, 30 Sep 2004 19:00:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pattern-match/m-p/3391115#M199151</guid>
      <dc:creator>Rahul_13</dc:creator>
      <dc:date>2004-09-30T19:00:00Z</dc:date>
    </item>
    <item>
      <title>Re: pattern match</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pattern-match/m-p/3391116#M199152</link>
      <description>Hi Rahul,&lt;BR /&gt;&lt;BR /&gt;Not a great script. As long as the ID stuff looks like &lt;ID&gt;&lt;SOMENUMBER&gt;&lt;/SOMENUMBER&gt;, then it will work. If you have some junk in place of &lt;SOMENUMBER&gt;, then you will see junk files getting created. So, try it in a test directory. May someone come up with a nicer one.&lt;BR /&gt;&lt;BR /&gt;grep "&lt;ID&gt;" data|sort |uniq|while read i&lt;BR /&gt;do&lt;BR /&gt;FILE=$(echo "$i" |sed -e 's/&amp;gt;//g' -e 's/echo $FILE&lt;BR /&gt;sed -n -e '/&lt;ID&gt;'$FILE'&amp;lt;\/ID&amp;gt;/,/&lt;ID&gt;/p' data |sed  -e '/&lt;ID&gt;*/d'  &amp;gt;&amp;gt; $FILE.out&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;-Sri&lt;/ID&gt;&lt;/ID&gt;&lt;/ID&gt;&lt;/ID&gt;&lt;/SOMENUMBER&gt;&lt;/ID&gt;</description>
      <pubDate>Thu, 30 Sep 2004 19:25:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pattern-match/m-p/3391116#M199152</guid>
      <dc:creator>Sridhar Bhaskarla</dc:creator>
      <dc:date>2004-09-30T19:25:52Z</dc:date>
    </item>
    <item>
      <title>Re: pattern match</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pattern-match/m-p/3391117#M199153</link>
      <description>for NUM in 1 2 3 4&lt;BR /&gt;do&lt;BR /&gt;  sed -n "/\&lt;ID&gt;$NUM\&amp;lt;\/ID\&amp;gt;/,/\&lt;ID&gt;.*&amp;lt;\/ID\&amp;gt;/p" 1 | grep -v ID &amp;gt; ID.$NUM.out&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Better scripters are around. but hey, it works :-)&lt;/ID&gt;&lt;/ID&gt;</description>
      <pubDate>Thu, 30 Sep 2004 19:27:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pattern-match/m-p/3391117#M199153</guid>
      <dc:creator>Sundar_7</dc:creator>
      <dc:date>2004-09-30T19:27:46Z</dc:date>
    </item>
    <item>
      <title>Re: pattern match</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pattern-match/m-p/3391118#M199154</link>
      <description>Here is my attempt in perl. Lines that follow &lt;ID&gt;&lt;NUMBER&gt;&lt;/NUMBER&gt; chunk will be written into chunk_&lt;NUMBER&gt;.txt file.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt; &lt;BR /&gt;open(FH, "&amp;lt; file") or die "$!";&lt;BR /&gt; &lt;BR /&gt;# Slurp the whole file&lt;BR /&gt;undef $/;&lt;BR /&gt;$file = &lt;FH&gt;;&lt;BR /&gt; &lt;BR /&gt;# Separate file into chunks starting with &lt;ID&gt;&lt;NUMBER&gt;&lt;/NUMBER&gt;&lt;BR /&gt;@chunks = split(/(?=\&lt;ID&gt;\d+\&amp;lt;\/ID\&amp;gt;)/, $file);&lt;BR /&gt; &lt;BR /&gt;for $chunk (@chunks) {&lt;BR /&gt;        # For each chunk extract its ID number and lines that follow&lt;BR /&gt;        ($id, $chunk) = ($chunk =~ /^\&lt;ID&gt;(\d+)\&amp;lt;\/ID\&amp;gt;\n(.+)$/sm);&lt;BR /&gt; &lt;BR /&gt;        # Append each chunk into a file called chunk_&lt;NUMBER&gt;.txt&lt;BR /&gt;        open(CHUNK, "&amp;gt;&amp;gt; chunk_${id}.txt") or die "$!";&lt;BR /&gt;        print CHUNK "$chunk";&lt;BR /&gt;        close(CHUNK);&lt;BR /&gt;}&lt;BR /&gt; &lt;BR /&gt;close(FH);&lt;/NUMBER&gt;&lt;/ID&gt;&lt;/ID&gt;&lt;/ID&gt;&lt;/FH&gt;&lt;/NUMBER&gt;&lt;/ID&gt;</description>
      <pubDate>Thu, 30 Sep 2004 21:44:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pattern-match/m-p/3391118#M199154</guid>
      <dc:creator>Ermin Borovac</dc:creator>
      <dc:date>2004-09-30T21:44:46Z</dc:date>
    </item>
    <item>
      <title>Re: pattern match</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pattern-match/m-p/3391119#M199155</link>
      <description>We can do with scripting as,&lt;BR /&gt;&lt;BR /&gt;script &lt;INPUTFILENAME&gt;&lt;BR /&gt;&lt;BR /&gt;so that it will create inputfilename.&lt;NUMBER&gt;&lt;BR /&gt;&lt;BR /&gt;every file contains in between patterns of &lt;ID&gt;&lt;ANYNUMBER&gt;&lt;/ANYNUMBER&gt; there.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;index=0&lt;BR /&gt;&lt;BR /&gt;# input file&lt;BR /&gt;testfile=$1&lt;BR /&gt; &lt;BR /&gt;fun()&lt;BR /&gt;{&lt;BR /&gt;  # Line&lt;BR /&gt;  ln="$1"&lt;BR /&gt;  &lt;BR /&gt;  if [[ $( echo $ln | grep '&lt;ID&gt;[0-9]&lt;/ID&gt;' | wc -l ) -ne 1 ]]&lt;BR /&gt;  then&lt;BR /&gt;     echo $ln &amp;gt;&amp;gt; $testfile.$index&lt;BR /&gt;  else&lt;BR /&gt;    let index=index+1&lt;BR /&gt;  fi&lt;BR /&gt;  &lt;BR /&gt;}  &lt;BR /&gt;&lt;BR /&gt;# main loop&lt;BR /&gt;while read line; do&lt;BR /&gt;&lt;BR /&gt; fun $line&lt;BR /&gt; &lt;BR /&gt;done &amp;lt; $testfile &lt;BR /&gt;&lt;BR /&gt;# exit&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;HTH.&lt;/ID&gt;&lt;/NUMBER&gt;&lt;/INPUTFILENAME&gt;</description>
      <pubDate>Fri, 01 Oct 2004 00:23:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pattern-match/m-p/3391119#M199155</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-10-01T00:23:57Z</dc:date>
    </item>
    <item>
      <title>Re: pattern match</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pattern-match/m-p/3391120#M199156</link>
      <description>It appears to be an XML file. So it may be dangerous to assume that &lt;BR /&gt;"&lt;ID&gt;num&lt;/ID&gt;" is on a single line.&lt;BR /&gt;&lt;BR /&gt;Check out using XML::Twig module of perl</description>
      <pubDate>Fri, 01 Oct 2004 08:56:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pattern-match/m-p/3391120#M199156</guid>
      <dc:creator>Rangarajan Radhakrishna</dc:creator>
      <dc:date>2004-10-01T08:56:00Z</dc:date>
    </item>
  </channel>
</rss>

