<?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: reformat the flatfile in unix using cut command in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/reformat-the-flatfile-in-unix-using-cut-command/m-p/4136158#M724540</link>
    <description>Thank you JRF and Dennis,&lt;BR /&gt;&lt;BR /&gt;Could you please tell me if i need to code this awk command in unix shell script?&lt;BR /&gt;&lt;BR /&gt;And moreover could you please tell me what does OFS mean?&lt;BR /&gt;&lt;BR /&gt;does substr($0,11,40) give 11th character to 40th character of each line in the input file?&lt;BR /&gt;&lt;BR /&gt;Could you please clarify these.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Sasi</description>
    <pubDate>Mon, 28 Jan 2008 05:16:57 GMT</pubDate>
    <dc:creator>sasikala</dc:creator>
    <dc:date>2008-01-28T05:16:57Z</dc:date>
    <item>
      <title>reformat the flatfile in unix using cut command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/reformat-the-flatfile-in-unix-using-cut-command/m-p/4136155#M724537</link>
      <description>Hi ,&lt;BR /&gt;&lt;BR /&gt;I have a flatfile called a_M having 2 records in it the below content wherein the single record is scattered into 2 lines.&lt;BR /&gt;&lt;BR /&gt;a_M&lt;BR /&gt;====&lt;BR /&gt;0001    13   3   HP Product and Pricing System        ^M&lt;BR /&gt;0001    16   5   HP  Product                         ^M&lt;BR /&gt;&lt;BR /&gt;I need to reformat it and create a new file called b_M.$timestamp.&lt;BR /&gt;&lt;BR /&gt;For this I have created a unix shell script with the below commands. But inthe output file i am getting some junk values. It looks if there is a space in the line the cut command does not take the proper column value. &lt;BR /&gt;&lt;BR /&gt;Could anyone please help me out on this as it is very urgent.&lt;BR /&gt;&lt;BR /&gt;#!/bin/ksh&lt;BR /&gt;&lt;BR /&gt;for i in `cat a_M`&lt;BR /&gt;do&lt;BR /&gt;    b=`echo $i | cut -c1-4`&lt;BR /&gt;    c=`echo $i | cut -c17-50`&lt;BR /&gt;&lt;BR /&gt;    echo "FAM;A;"$b";";"$c &amp;gt;&amp;gt; b_M&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;timestamp=$( date +%d%m%y%H%M%S )&lt;BR /&gt;mv b_M b_M."$timestamp"&lt;BR /&gt;#END OF PROG&lt;BR /&gt;&lt;BR /&gt;The ideal output should be &lt;BR /&gt;=============================&lt;BR /&gt;FAM;A;0001;HP Product and Pricing System&lt;BR /&gt;FAM;A;0001;HP  Product&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Sasi</description>
      <pubDate>Sun, 27 Jan 2008 14:46:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/reformat-the-flatfile-in-unix-using-cut-command/m-p/4136155#M724537</guid>
      <dc:creator>sasikala</dc:creator>
      <dc:date>2008-01-27T14:46:00Z</dc:date>
    </item>
    <item>
      <title>Re: reformat the flatfile in unix using cut command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/reformat-the-flatfile-in-unix-using-cut-command/m-p/4136156#M724538</link>
      <description>&lt;!--!*#--&gt;Hi Sasi:&lt;BR /&gt;&lt;BR /&gt;You have several problems.  Your 'for' loop will execute for every "word" in the file --- not what you want.  Instead you want to read a line at a time.  You could do this:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;while read i&lt;BR /&gt;do&lt;BR /&gt;    b=`echo $i | cut -c1-4`&lt;BR /&gt;    c=`echo $i | cut -c11-50`&lt;BR /&gt;    echo "FAM;A;"$b";"$c&lt;BR /&gt;done &amp;lt; a_M &amp;gt; b_M&lt;BR /&gt;&lt;BR /&gt;Notice that the input is read from the file named "a_M" into the variable "i" one line at a time.  Any output of the 'while' loop is redirected to the file named "b_M".&lt;BR /&gt;&lt;BR /&gt;You show a "^M" in your input file.  This is a carriage-return character and means that your file came from a Windows platform.  UNIX doesn't end lines with the carriage-return plus newline characters; only with a newline.  You can strip these by doing:&lt;BR /&gt;&lt;BR /&gt;# dos2ux a_M &amp;gt; a_M.fixed&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Sun, 27 Jan 2008 15:24:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/reformat-the-flatfile-in-unix-using-cut-command/m-p/4136156#M724538</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-01-27T15:24:01Z</dc:date>
    </item>
    <item>
      <title>Re: reformat the flatfile in unix using cut command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/reformat-the-flatfile-in-unix-using-cut-command/m-p/4136157#M724539</link>
      <description>I just about never use cut(1) since it is so limited.  You may want to consider using awk(1).&lt;BR /&gt;&lt;BR /&gt;Taking the comments made by JRF about dos2ux(1):&lt;BR /&gt;&lt;BR /&gt;timestamp=$(date +%d%m%y%H%M%S)&lt;BR /&gt;dos2ux a_M | awk -v OFS=";" '&lt;BR /&gt;{&lt;BR /&gt;num = substr($0, 1, 4)&lt;BR /&gt;name = substr($0, 11, 40)&lt;BR /&gt;print "FAM;A", num, name&lt;BR /&gt;} ' &amp;gt; b_M.$timestamp&lt;BR /&gt;&lt;BR /&gt;&amp;gt;echo "FAM;A;"$b";";"$c &amp;gt;&amp;gt; b_M&lt;BR /&gt;&lt;BR /&gt;You shouldn't "stutter" your quoting, do it in one go:&lt;BR /&gt;echo "FAM;A;$b;$c"</description>
      <pubDate>Mon, 28 Jan 2008 04:31:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/reformat-the-flatfile-in-unix-using-cut-command/m-p/4136157#M724539</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-01-28T04:31:31Z</dc:date>
    </item>
    <item>
      <title>Re: reformat the flatfile in unix using cut command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/reformat-the-flatfile-in-unix-using-cut-command/m-p/4136158#M724540</link>
      <description>Thank you JRF and Dennis,&lt;BR /&gt;&lt;BR /&gt;Could you please tell me if i need to code this awk command in unix shell script?&lt;BR /&gt;&lt;BR /&gt;And moreover could you please tell me what does OFS mean?&lt;BR /&gt;&lt;BR /&gt;does substr($0,11,40) give 11th character to 40th character of each line in the input file?&lt;BR /&gt;&lt;BR /&gt;Could you please clarify these.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Sasi</description>
      <pubDate>Mon, 28 Jan 2008 05:16:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/reformat-the-flatfile-in-unix-using-cut-command/m-p/4136158#M724540</guid>
      <dc:creator>sasikala</dc:creator>
      <dc:date>2008-01-28T05:16:57Z</dc:date>
    </item>
    <item>
      <title>Re: reformat the flatfile in unix using cut command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/reformat-the-flatfile-in-unix-using-cut-command/m-p/4136159#M724541</link>
      <description>&amp;gt;Could you please tell me if I need to code this awk command in unix shell script?&lt;BR /&gt;&lt;BR /&gt;You might as well, that was my intention.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;And moreover could you please tell me what does OFS mean?&lt;BR /&gt;&lt;BR /&gt;Output Field Separator, that supplies the ";".&lt;BR /&gt;&lt;BR /&gt;&amp;gt;does substr($0,11,40) give 11th character to 40th character of each line in the input file?&lt;BR /&gt;&lt;BR /&gt;No, it starts at 11 for 40 chars.  Indexing starts at 1.  (Your original question said 17 but JRF had 11.)&lt;BR /&gt;&lt;A href="http://docs.hp.com/en/B2355-60130/awk.1.html" target="_blank"&gt;http://docs.hp.com/en/B2355-60130/awk.1.html&lt;/A&gt;</description>
      <pubDate>Mon, 28 Jan 2008 09:51:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/reformat-the-flatfile-in-unix-using-cut-command/m-p/4136159#M724541</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-01-28T09:51:03Z</dc:date>
    </item>
    <item>
      <title>Re: reformat the flatfile in unix using cut command</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/reformat-the-flatfile-in-unix-using-cut-command/m-p/4136160#M724542</link>
      <description>Thanks Dennis,&lt;BR /&gt;&lt;BR /&gt;In unix itself I could achieve this as below. The space was considered when I use "$i" in echo command. Previously I didnt use "" for $i. Hence the problem. Thank you for your help.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;while read i&lt;BR /&gt;do&lt;BR /&gt;    b=`echo "$i" | cut -c1-4`&lt;BR /&gt;    c=`echo "$i" | cut -c11-50`&lt;BR /&gt;    echo "FAM;A;"$b";"$c&lt;BR /&gt;done &amp;lt; a_M &amp;gt; b_M&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Sasi&lt;BR /&gt;</description>
      <pubDate>Mon, 28 Jan 2008 09:58:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/reformat-the-flatfile-in-unix-using-cut-command/m-p/4136160#M724542</guid>
      <dc:creator>sasikala</dc:creator>
      <dc:date>2008-01-28T09:58:07Z</dc:date>
    </item>
  </channel>
</rss>

