<?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: awk multiline record print in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-multiline-record-print/m-p/3604249#M824652</link>
    <description>&lt;BR /&gt;"If it is a four-line-record"&lt;BR /&gt;&lt;BR /&gt;This is critical. How do you define that.&lt;BR /&gt;My first solution is a fairly rigirous test, only creating a new file under specific conditions.&lt;BR /&gt;&lt;BR /&gt;If dor example you 'know' that there will always be a four-line-record as soon as you see a line starting with 'dn:' then the solution simplyfies a lot. For example:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; awk '/^dn:/{x=4;i++;f="xx_"i".tmp"; while (x--) {print $0&amp;gt;f; getline} }' &amp;lt; x&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;hth,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
    <pubDate>Mon, 15 Aug 2005 16:36:44 GMT</pubDate>
    <dc:creator>Hein van den Heuvel</dc:creator>
    <dc:date>2005-08-15T16:36:44Z</dc:date>
    <item>
      <title>awk multiline record print</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-multiline-record-print/m-p/3604244#M824647</link>
      <description>Hi,&lt;BR /&gt;I have a multiline text file like below:&lt;BR /&gt;&lt;BR /&gt;dn:djkjdf jdkjkjf&lt;BR /&gt;homedir kkjkjk&lt;BR /&gt;shell dkjkfjkgjg&lt;BR /&gt;userpasswd kkjk&lt;BR /&gt;&lt;BR /&gt;dn:djkjdf jdkjkjf&lt;BR /&gt;homedir kkjkjk&lt;BR /&gt;shell dkjkfjkgjg&lt;BR /&gt;userpasswd kkjk&lt;BR /&gt;&lt;BR /&gt;The file has hundreds of 4-line blocks like above. What I want is to output each 4-line block to each different file. If it is a four-line-record I want to print each record to a different file.&lt;BR /&gt;&lt;BR /&gt;Please advise.&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 15 Aug 2005 15:42:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-multiline-record-print/m-p/3604244#M824647</guid>
      <dc:creator>Yashy</dc:creator>
      <dc:date>2005-08-15T15:42:46Z</dc:date>
    </item>
    <item>
      <title>Re: awk multiline record print</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-multiline-record-print/m-p/3604245#M824648</link>
      <description>Yashy,&lt;BR /&gt;&lt;BR /&gt;Here's a simple awk script inside a for loop that you can use to separate each of the 4-line blocks into separate output streams.&lt;BR /&gt;&lt;BR /&gt;# for i in &lt;YOUR_FILENAME&gt;; do&lt;BR /&gt;&amp;gt; awk 'BEGIN{FS=""} {print $0 &amp;gt; "block"NR".out"}' $i&lt;BR /&gt;&amp;gt; done&lt;BR /&gt;&lt;/YOUR_FILENAME&gt;</description>
      <pubDate>Mon, 15 Aug 2005 16:06:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-multiline-record-print/m-p/3604245#M824648</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2005-08-15T16:06:27Z</dc:date>
    </item>
    <item>
      <title>Re: awk multiline record print</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-multiline-record-print/m-p/3604246#M824649</link>
      <description>Typo in the last posting. Change the "FS" to "RS" in the "BEGIN" section of the awk construct i.e.&lt;BR /&gt;&lt;BR /&gt;# for i in &lt;YOUR_FILENAME&gt;; do&lt;BR /&gt;&amp;gt; awk 'BEGIN{RS=""} {print $0 &amp;gt; "block"NR".out"}' $i&lt;BR /&gt;&amp;gt; done&lt;BR /&gt;&lt;/YOUR_FILENAME&gt;</description>
      <pubDate>Mon, 15 Aug 2005 16:09:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-multiline-record-print/m-p/3604246#M824649</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2005-08-15T16:09:02Z</dc:date>
    </item>
    <item>
      <title>Re: awk multiline record print</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-multiline-record-print/m-p/3604247#M824650</link>
      <description>&lt;BR /&gt;In a 'one-liner':&lt;BR /&gt;&lt;BR /&gt;awk '/^dn/{n=NR;dn=$0;h=s=""}/^home/{h=$0}/^she/{s=$0}/^user/&amp;amp;&amp;amp;(NR-n==3){i++; f="xx_" i ".tmp"; print dn "\n" h "\n" s "\n" $0 &amp;gt; f  }' &amp;lt; x&lt;BR /&gt;&lt;BR /&gt;In a script use:&lt;BR /&gt;/^dn/{n=NR;dn=$0;h=s=""}&lt;BR /&gt;/^home/{h=$0}&lt;BR /&gt;/^shel/{s=$0}&lt;BR /&gt;/^user/&amp;amp;&amp;amp;(NR-n==3){&lt;BR /&gt;   i++; &lt;BR /&gt;   f="xx_" i ".tmp"; &lt;BR /&gt;   print dn "\n" h "\n" s "\n" $0 &amp;gt; f  &lt;BR /&gt;   }&lt;BR /&gt;&lt;BR /&gt;What happens?&lt;BR /&gt;- If we see a line starting with dn then remember the line number, remember the line in dn, clear home and shell variables.&lt;BR /&gt;- Remember home and shell in h and s if you see them&lt;BR /&gt;- If you see a line starting with user, and it is 3 lines after dn, then &lt;BR /&gt;-- increment the file number&lt;BR /&gt;-- generate a fresh file name&lt;BR /&gt;-- print all four line onto the new file name&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 15 Aug 2005 16:17:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-multiline-record-print/m-p/3604247#M824650</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2005-08-15T16:17:31Z</dc:date>
    </item>
    <item>
      <title>Re: awk multiline record print</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-multiline-record-print/m-p/3604248#M824651</link>
      <description>If all these 4-line blocks are in a single file then you don't need the "for" loop.&lt;BR /&gt;&lt;BR /&gt;Use the awk construct within a for loop only if you want to operate on multiple files within a directory. Otherwise the awk statement by itself will do what you want:&lt;BR /&gt;&lt;BR /&gt;# awk 'BEGIN{RS=""} {print $0 &amp;gt; "block"NR".out"}' &lt;YOUR_FILENAME&gt;&lt;BR /&gt;&lt;BR /&gt;cheers!!!&lt;/YOUR_FILENAME&gt;</description>
      <pubDate>Mon, 15 Aug 2005 16:26:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-multiline-record-print/m-p/3604248#M824651</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2005-08-15T16:26:40Z</dc:date>
    </item>
    <item>
      <title>Re: awk multiline record print</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-multiline-record-print/m-p/3604249#M824652</link>
      <description>&lt;BR /&gt;"If it is a four-line-record"&lt;BR /&gt;&lt;BR /&gt;This is critical. How do you define that.&lt;BR /&gt;My first solution is a fairly rigirous test, only creating a new file under specific conditions.&lt;BR /&gt;&lt;BR /&gt;If dor example you 'know' that there will always be a four-line-record as soon as you see a line starting with 'dn:' then the solution simplyfies a lot. For example:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; awk '/^dn:/{x=4;i++;f="xx_"i".tmp"; while (x--) {print $0&amp;gt;f; getline} }' &amp;lt; x&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;hth,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Mon, 15 Aug 2005 16:36:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-multiline-record-print/m-p/3604249#M824652</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2005-08-15T16:36:44Z</dc:date>
    </item>
    <item>
      <title>Re: awk multiline record print</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-multiline-record-print/m-p/3604250#M824653</link>
      <description>Thanks. It is working can you please explain more about the variable and the interpolation of them.&lt;BR /&gt;&lt;BR /&gt;yashy</description>
      <pubDate>Wed, 17 Aug 2005 01:01:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-multiline-record-print/m-p/3604250#M824653</guid>
      <dc:creator>Yashy</dc:creator>
      <dc:date>2005-08-17T01:01:34Z</dc:date>
    </item>
    <item>
      <title>Re: awk multiline record print</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-multiline-record-print/m-p/3604251#M824654</link>
      <description>To explain this,&lt;BR /&gt;&lt;BR /&gt;# awk '/^dn:/{x=4;i++;f="xx_"i".tmp"; while (x--) {print $0&amp;gt;f; getline} }' &amp;lt; x&lt;BR /&gt;&lt;BR /&gt;a) It will read from a file called x&lt;BR /&gt;b) awk will search a line with dn string&lt;BR /&gt;c) It will collect 4 lines from the line starting with dn:&lt;BR /&gt;d) New file name is assigned as, xx_1.tmp 1 will be increased with i variable. This file is assigned to f variable.&lt;BR /&gt;e) print $0 &amp;gt; f will write as, print $0 &amp;gt; xx_1.tmp&lt;BR /&gt;&lt;BR /&gt;File name will be varied with 1..n.&lt;BR /&gt;&lt;BR /&gt;hth.</description>
      <pubDate>Wed, 17 Aug 2005 03:20:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-multiline-record-print/m-p/3604251#M824654</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-08-17T03:20:27Z</dc:date>
    </item>
    <item>
      <title>Re: awk multiline record print</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-multiline-record-print/m-p/3604252#M824655</link>
      <description>Hi,&lt;BR /&gt;Are there empty lines in the file ? If not, why not use split -l 4 (split a file into 4-lines pieces).&lt;BR /&gt;&lt;BR /&gt;If there are empty lines, supress those lines (there is several ways to do that) and then use split.&lt;BR /&gt;&lt;BR /&gt;If it not is possible to just to supress lines, use a simple script as:&lt;BR /&gt;&lt;BR /&gt;awk '/^dn/ {print $0; getline; print $0; getline; print $0; getline; print $0;}' file &amp;gt;outfile&lt;BR /&gt;&lt;BR /&gt;and, then use split -l 4 on outfile.</description>
      <pubDate>Wed, 17 Aug 2005 15:05:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-multiline-record-print/m-p/3604252#M824655</guid>
      <dc:creator>Leif Halvarsson_2</dc:creator>
      <dc:date>2005-08-17T15:05:21Z</dc:date>
    </item>
    <item>
      <title>Re: awk multiline record print</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-multiline-record-print/m-p/3604253#M824656</link>
      <description>Thanks everyone. It works well.&lt;BR /&gt;Thanks Leif. I already know about the split option and I was actually looking for an awk option. Thanks again everyone.&lt;BR /&gt;&lt;BR /&gt;Yashy</description>
      <pubDate>Tue, 23 Aug 2005 00:21:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-multiline-record-print/m-p/3604253#M824656</guid>
      <dc:creator>Yashy</dc:creator>
      <dc:date>2005-08-23T00:21:01Z</dc:date>
    </item>
  </channel>
</rss>

