<?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: scripting question in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/3281337#M715451</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Here is one way to do it in Perl:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;while (&amp;lt;&amp;gt;)                             &lt;BR /&gt;{                                   &lt;BR /&gt;    if (/^H/){&lt;BR /&gt;        close (OUTF);&lt;BR /&gt;        $count++;                   &lt;BR /&gt;        $outfile="FILE." . $count;&lt;BR /&gt;        open(OUTF,"&amp;gt;$outfile") or die "Can't open output file $outfile";&lt;BR /&gt;     }                                &lt;BR /&gt;     print OUTF $_;                &lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;JP&lt;BR /&gt;</description>
    <pubDate>Wed, 19 May 2004 15:58:41 GMT</pubDate>
    <dc:creator>John Poff</dc:creator>
    <dc:date>2004-05-19T15:58:41Z</dc:date>
    <item>
      <title>scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/3281333#M715447</link>
      <description>Hi all,&lt;BR /&gt;&lt;BR /&gt;Here's what I need help with:&lt;BR /&gt;I receive a data file with several records inside and each record has several lines.&lt;BR /&gt;&lt;BR /&gt;The file follows the following format:&lt;BR /&gt;H0001&lt;BR /&gt;D0001&lt;BR /&gt;D0001&lt;BR /&gt;D0001&lt;BR /&gt;T0001&lt;BR /&gt;H0002&lt;BR /&gt;D0002&lt;BR /&gt;D0002&lt;BR /&gt;T0002&lt;BR /&gt;H0003&lt;BR /&gt;...., etc.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The H indicates a Header Record, the D a Detail Record and T a Terminator Record.&lt;BR /&gt;The H,D or T is actually the first character of the line and the number of Detail lines varies.&lt;BR /&gt;&lt;BR /&gt;What I need to do is split the single file into multiple files so that each H-D-D-D-T section of the file is in a separate file with a different name. The file name is doesn't matter much, perhaps a file.timestamp format.   I'm not getting very far with it and was wondering if I could get some help or direction.&lt;BR /&gt;&lt;BR /&gt;I've got perl on the system but I'm not very conversant with it, a shell script would be prefered for longer term support.  Or, of course, I could start learning perl ;-)&lt;BR /&gt;&lt;BR /&gt;Thanks a Lot&lt;BR /&gt;&lt;BR /&gt;Gary</description>
      <pubDate>Wed, 19 May 2004 15:35:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/3281333#M715447</guid>
      <dc:creator>Gary Glick</dc:creator>
      <dc:date>2004-05-19T15:35:57Z</dc:date>
    </item>
    <item>
      <title>Re: scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/3281334#M715448</link>
      <description>just a quicky so it is untested&lt;BR /&gt;&lt;BR /&gt;file="f"&lt;BR /&gt;num=0&lt;BR /&gt;&lt;BR /&gt;cat yourFile |&lt;BR /&gt;while read var&lt;BR /&gt;do&lt;BR /&gt;case $var in&lt;BR /&gt;H*) ((num = $num + 1))&lt;BR /&gt;print "$var" &amp;gt; ${file}${num}&lt;BR /&gt;;;&lt;BR /&gt;D*|H*) print "$var" &amp;gt;&amp;gt; ${file}${num}&lt;BR /&gt;;;&lt;BR /&gt;esac&lt;BR /&gt;done</description>
      <pubDate>Wed, 19 May 2004 15:45:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/3281334#M715448</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2004-05-19T15:45:09Z</dc:date>
    </item>
    <item>
      <title>Re: scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/3281335#M715449</link>
      <description>Hmmm.....&lt;BR /&gt;&lt;BR /&gt;Here's something off the top of my head ---&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;while read LINE&lt;BR /&gt;do&lt;BR /&gt;FIRST=$(echo $LINE | cut -c 1)&lt;BR /&gt;if [ "${FIRST}" = "H" ] ; then&lt;BR /&gt;FILE=H_$(date +%m%d%Y)_$(date +%H%M%S)&lt;BR /&gt;echo ${LINE} &amp;gt;&amp;gt; ${FILE}&lt;BR /&gt;else&lt;BR /&gt;echo ${LINE} &amp;gt;&amp;gt; ${FILE}&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;This should give you a file named like H_05192004_154715 starting with an H line, it will write to that file until it finds another record with H as the first character then it will start a new file.  I haven't tested, but I think it should work.</description>
      <pubDate>Wed, 19 May 2004 15:48:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/3281335#M715449</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2004-05-19T15:48:55Z</dc:date>
    </item>
    <item>
      <title>Re: scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/3281336#M715450</link>
      <description>awk might be a bit faster&lt;BR /&gt;&lt;BR /&gt;cat yourFile | awk '&lt;BR /&gt;BEGIN {name="f";num=0;}&lt;BR /&gt;/^H/ {&lt;BR /&gt;num += 1;&lt;BR /&gt;fname=sprintf("%s%d",name,num);&lt;BR /&gt;print $0 &amp;gt; fname;&lt;BR /&gt;next;&lt;BR /&gt;}&lt;BR /&gt;/^D/ {&lt;BR /&gt;print $0 &amp;gt;&amp;gt; fname&lt;BR /&gt;next;&lt;BR /&gt;}&lt;BR /&gt;/^T/ {&lt;BR /&gt;print $0 &amp;gt;&amp;gt; fname&lt;BR /&gt;}&lt;BR /&gt;</description>
      <pubDate>Wed, 19 May 2004 15:55:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/3281336#M715450</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2004-05-19T15:55:05Z</dc:date>
    </item>
    <item>
      <title>Re: scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/3281337#M715451</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Here is one way to do it in Perl:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;while (&amp;lt;&amp;gt;)                             &lt;BR /&gt;{                                   &lt;BR /&gt;    if (/^H/){&lt;BR /&gt;        close (OUTF);&lt;BR /&gt;        $count++;                   &lt;BR /&gt;        $outfile="FILE." . $count;&lt;BR /&gt;        open(OUTF,"&amp;gt;$outfile") or die "Can't open output file $outfile";&lt;BR /&gt;     }                                &lt;BR /&gt;     print OUTF $_;                &lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;JP&lt;BR /&gt;</description>
      <pubDate>Wed, 19 May 2004 15:58:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/3281337#M715451</guid>
      <dc:creator>John Poff</dc:creator>
      <dc:date>2004-05-19T15:58:41Z</dc:date>
    </item>
    <item>
      <title>Re: scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/3281338#M715452</link>
      <description>Gary -&lt;BR /&gt;We do just this thing on a similar data file.&lt;BR /&gt;Attached is a snip of the process with our naming convention edited.&lt;BR /&gt;The array allows the cylcle through and sed of the lines you want printed to separate files.&lt;BR /&gt;Not this snip is based on each new record starting with H, and H does not appear in the data portion.&lt;BR /&gt;&lt;BR /&gt;Best of luck.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;dl</description>
      <pubDate>Wed, 19 May 2004 16:13:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/3281338#M715452</guid>
      <dc:creator>Dave La Mar</dc:creator>
      <dc:date>2004-05-19T16:13:59Z</dc:date>
    </item>
    <item>
      <title>Re: scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/3281339#M715453</link>
      <description>perl -ne 'if(/H00(\d+)/.../T00($1)/){open O, "&amp;gt;&amp;gt;$1";print O;close O;}' inputfile&lt;BR /&gt;&lt;BR /&gt;This will create files named 1,2,3 etc. The numbers will correspond to the end of the H.&lt;BR /&gt;&lt;BR /&gt;One of the other ways might be better. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 19 May 2004 16:17:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/3281339#M715453</guid>
      <dc:creator>Marvin Strong</dc:creator>
      <dc:date>2004-05-19T16:17:55Z</dc:date>
    </item>
    <item>
      <title>Re: scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/3281340#M715454</link>
      <description>Hi Gary, &lt;BR /&gt;&lt;BR /&gt;My two lines awk script:&lt;BR /&gt;&lt;BR /&gt;awk '&lt;BR /&gt;/^H/ {count++ ; filename="prefix_" count}&lt;BR /&gt;{ print &amp;gt;&amp;gt; filename }' filein&lt;BR /&gt;&lt;BR /&gt;where "prefix_" is a prefix you want to name the out files.&lt;BR /&gt;&lt;BR /&gt;Frank.</description>
      <pubDate>Wed, 19 May 2004 16:28:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/3281340#M715454</guid>
      <dc:creator>Francisco J. Soler</dc:creator>
      <dc:date>2004-05-19T16:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/3281341#M715455</link>
      <description>Here's an updated version of my script.  This one DOES work, as I just had a chance to do some quick testing and debugging of it.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;COUNT=0&lt;BR /&gt;while read LINE&lt;BR /&gt;do&lt;BR /&gt;FIRST=$(echo $LINE | cut -c 1)&lt;BR /&gt;echo $FIRST ; if [ "${FIRST}" = "H" ] ; then&lt;BR /&gt;FILE=H_${COUNT}_$(date +%m%d%Y)_$(date +%H%M%S)&lt;BR /&gt;echo ${LINE} &amp;gt;&amp;gt; ${FILE}&lt;BR /&gt;let COUNT=$COUNT+1&lt;BR /&gt;else&lt;BR /&gt;echo ${LINE} &amp;gt;&amp;gt; ${FILE}&lt;BR /&gt;fi&lt;BR /&gt;done &amp;lt; datfile&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 19 May 2004 16:43:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/3281341#M715455</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2004-05-19T16:43:22Z</dc:date>
    </item>
    <item>
      <title>Re: scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/3281342#M715456</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;There must be an easy solution with csplit. I try from memory, so please don't hit me. ;-).&lt;BR /&gt;&lt;BR /&gt;hth,&lt;BR /&gt;&lt;BR /&gt;Michael&lt;BR /&gt;&lt;BR /&gt;csplit -f spl filetosplit /^H[0-9]*/</description>
      <pubDate>Wed, 19 May 2004 20:38:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/3281342#M715456</guid>
      <dc:creator>Michael Schulte zur Sur</dc:creator>
      <dc:date>2004-05-19T20:38:08Z</dc:date>
    </item>
    <item>
      <title>Re: scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/3281343#M715457</link>
      <description>thanks for all the responses.&lt;BR /&gt;I haven't had the opportunity to try them yet. I'll give 'em a shot tomorrow and see how it goes.&lt;BR /&gt;&lt;BR /&gt;Don't fret points will be forthcoming :D</description>
      <pubDate>Thu, 20 May 2004 15:36:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/3281343#M715457</guid>
      <dc:creator>Gary Glick</dc:creator>
      <dc:date>2004-05-20T15:36:53Z</dc:date>
    </item>
  </channel>
</rss>

