<?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: How to reformat a fixed length file using scripting? in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/how-to-reformat-a-fixed-length-file-using-scripting/m-p/3808329#M100033</link>
    <description>It's a bit difficult to tell from your file because I don't know if the records are actual text records terminated with a LF, CR, or a CR/LF pair or if they are indeed simply fixed-length records as you seem to imply. I don't know if your attachment is an accurate translation of the data or if you have passed it thru a filter or selected a particular output format. It would be helpful if you indicated if this is actual raw data and what is the record length.&lt;BR /&gt;&lt;BR /&gt;If the records are truly-fixed length w/o a normal record terminator then tools like grep, sed, or awk aren't going to very useful. Your best bet will be Perl because it can easily process fixed-length records as well as normal line-oriented text. Another option is to use dd to unblock the input records and attach a LF to each of these so that the more conventional tools (awk, grep, sed) can then be used.</description>
    <pubDate>Mon, 19 Jun 2006 22:06:08 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2006-06-19T22:06:08Z</dc:date>
    <item>
      <title>How to reformat a fixed length file using scripting?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-reformat-a-fixed-length-file-using-scripting/m-p/3808328#M100032</link>
      <description>&lt;!--!*#--&gt;Dear all,&lt;BR /&gt;&lt;BR /&gt;I face difficulties to code a script to do a file processing. I was given a file with fixed length records. &lt;BR /&gt;&lt;BR /&gt;My task now is to grep the line record that has the first character with the number 5 and need to substring the line starting from position 12 with a string length of 6 (12,6) to indicate the transaction date. &lt;BR /&gt;&lt;BR /&gt;Then the transaction date will be used to append at the end of the subsequent line of records that has the first character with number 6.&lt;BR /&gt;&lt;BR /&gt;The script has to detect for the change of transaction date in between the records. If there is another line starts with number 5 appear, then the same process has to be done to substring starts from position 12 and length 6.&lt;BR /&gt;&lt;BR /&gt;Then use the new transaction date to append to end of the line of the subsequent records that start with number 6.&lt;BR /&gt;&lt;BR /&gt;The new record format has to be output into a new file.&lt;BR /&gt;&lt;BR /&gt;I have attached a sample file for your understanding of how the file format look like.&lt;BR /&gt;&lt;BR /&gt;Is there a way where awk programming or normal shell script can accomplish this task?&lt;BR /&gt;&lt;BR /&gt;I hope the Unix gurus here can advise me. I will appreciate any help on this matter.&lt;BR /&gt;&lt;BR /&gt;Thank you.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Mel</description>
      <pubDate>Mon, 19 Jun 2006 21:26:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-reformat-a-fixed-length-file-using-scripting/m-p/3808328#M100032</guid>
      <dc:creator>Melvin Thong</dc:creator>
      <dc:date>2006-06-19T21:26:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to reformat a fixed length file using scripting?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-reformat-a-fixed-length-file-using-scripting/m-p/3808329#M100033</link>
      <description>It's a bit difficult to tell from your file because I don't know if the records are actual text records terminated with a LF, CR, or a CR/LF pair or if they are indeed simply fixed-length records as you seem to imply. I don't know if your attachment is an accurate translation of the data or if you have passed it thru a filter or selected a particular output format. It would be helpful if you indicated if this is actual raw data and what is the record length.&lt;BR /&gt;&lt;BR /&gt;If the records are truly-fixed length w/o a normal record terminator then tools like grep, sed, or awk aren't going to very useful. Your best bet will be Perl because it can easily process fixed-length records as well as normal line-oriented text. Another option is to use dd to unblock the input records and attach a LF to each of these so that the more conventional tools (awk, grep, sed) can then be used.</description>
      <pubDate>Mon, 19 Jun 2006 22:06:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-reformat-a-fixed-length-file-using-scripting/m-p/3808329#M100033</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2006-06-19T22:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to reformat a fixed length file using scripting?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-reformat-a-fixed-length-file-using-scripting/m-p/3808330#M100034</link>
      <description>If the file really is divided into lines like your attachment then you could use this-&lt;BR /&gt;&lt;BR /&gt;awk '/^5/{date=substr($0,12,6)}/^6/{sub("$",date)}//{print}' input &amp;gt; output&lt;BR /&gt;&lt;BR /&gt;Each time it sees a line with a leading 5 it remembers that as date.  Each time it sees a line with a leading 6 it appends the current value of date.</description>
      <pubDate>Tue, 20 Jun 2006 17:34:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-reformat-a-fixed-length-file-using-scripting/m-p/3808330#M100034</guid>
      <dc:creator>Mike Stroyan</dc:creator>
      <dc:date>2006-06-20T17:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to reformat a fixed length file using scripting?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-reformat-a-fixed-length-file-using-scripting/m-p/3808331#M100035</link>
      <description>I have tried to code using perl. It worked!&lt;BR /&gt;&lt;BR /&gt;Thanks to Clay and Mike for your replies.</description>
      <pubDate>Wed, 21 Jun 2006 06:15:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-reformat-a-fixed-length-file-using-scripting/m-p/3808331#M100035</guid>
      <dc:creator>Melvin Thong</dc:creator>
      <dc:date>2006-06-21T06:15:30Z</dc:date>
    </item>
  </channel>
</rss>

