<?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: field format in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/field-format/m-p/4437628#M661176</link>
    <description>cat myfile | while read line;do&lt;BR /&gt;typ=`echo $line | cut -d"," -f2`&lt;BR /&gt;date1=`echo $line | cut -d"," -f3`&lt;BR /&gt;date2=`echo $line | cut -d"," -f4`&lt;BR /&gt;time1=`echo $line | cut -d"," -f5`&lt;BR /&gt;time2=`echo $line | cut -d"," -f6`&lt;BR /&gt;&lt;BR /&gt;y1=`echo $date1 | cut -c 1-4`&lt;BR /&gt;m1=`echo $date1 | cut -c 5-6`&lt;BR /&gt;d1=`echo $date1 | cut -c 7-8`&lt;BR /&gt;h1=`echo $time1 | cut -c 1-2`&lt;BR /&gt;mm1=`echo $time1 | cut -c 3-4`&lt;BR /&gt;&lt;BR /&gt;y2=`echo $date2 | cut -c 1-4`&lt;BR /&gt;m2=`echo $date2 | cut -c 5-6`&lt;BR /&gt;d2=`echo $date2 | cut -c 7-8`&lt;BR /&gt;h2=`echo $time2 | cut -c 1-2`&lt;BR /&gt;mm2=`echo $time2 | cut -c 3-4`&lt;BR /&gt;&lt;BR /&gt;echo "${typ},${y1}-${m1}-${d1} ${h1}:${mm1},${y2}-${m2}-${d2} ${h2}:${mm2}"&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Hope this helps.. it is not most elegant but easy to follow...</description>
    <pubDate>Thu, 11 Jun 2009 13:33:39 GMT</pubDate>
    <dc:creator>Mel Burslan</dc:creator>
    <dc:date>2009-06-11T13:33:39Z</dc:date>
    <item>
      <title>field format</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/field-format/m-p/4437626#M661174</link>
      <description>Hi, &lt;BR /&gt;I have a file in the format&lt;BR /&gt;&lt;BR /&gt;1,type1,20090510,20090511,1000,1100&lt;BR /&gt;2,type2,20090611,20090714,1200,1300&lt;BR /&gt;3,type3,20090414,20090515,1600,1700&lt;BR /&gt;&lt;BR /&gt;I want the file to be present in this format:&lt;BR /&gt;type1,2009-05-10 10:00,2009-05-11 11:00&lt;BR /&gt;type2,2009-06-11 12:00,2009-07-14 13:00&lt;BR /&gt;type3,2009-04-14 16:00,2009-05-15 17:00&lt;BR /&gt;&lt;BR /&gt;i.e the first field to be removed and the date and time stamps to be merged.Please help</description>
      <pubDate>Thu, 11 Jun 2009 13:17:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/field-format/m-p/4437626#M661174</guid>
      <dc:creator>viseshu</dc:creator>
      <dc:date>2009-06-11T13:17:59Z</dc:date>
    </item>
    <item>
      <title>Re: field format</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/field-format/m-p/4437627#M661175</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;awk -F, '{print $2","$3,$5","$4,$6}' /file&lt;BR /&gt;&lt;BR /&gt;should do the trick.&lt;BR /&gt;&lt;BR /&gt;Richard</description>
      <pubDate>Thu, 11 Jun 2009 13:32:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/field-format/m-p/4437627#M661175</guid>
      <dc:creator>Richard Hepworth</dc:creator>
      <dc:date>2009-06-11T13:32:45Z</dc:date>
    </item>
    <item>
      <title>Re: field format</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/field-format/m-p/4437628#M661176</link>
      <description>cat myfile | while read line;do&lt;BR /&gt;typ=`echo $line | cut -d"," -f2`&lt;BR /&gt;date1=`echo $line | cut -d"," -f3`&lt;BR /&gt;date2=`echo $line | cut -d"," -f4`&lt;BR /&gt;time1=`echo $line | cut -d"," -f5`&lt;BR /&gt;time2=`echo $line | cut -d"," -f6`&lt;BR /&gt;&lt;BR /&gt;y1=`echo $date1 | cut -c 1-4`&lt;BR /&gt;m1=`echo $date1 | cut -c 5-6`&lt;BR /&gt;d1=`echo $date1 | cut -c 7-8`&lt;BR /&gt;h1=`echo $time1 | cut -c 1-2`&lt;BR /&gt;mm1=`echo $time1 | cut -c 3-4`&lt;BR /&gt;&lt;BR /&gt;y2=`echo $date2 | cut -c 1-4`&lt;BR /&gt;m2=`echo $date2 | cut -c 5-6`&lt;BR /&gt;d2=`echo $date2 | cut -c 7-8`&lt;BR /&gt;h2=`echo $time2 | cut -c 1-2`&lt;BR /&gt;mm2=`echo $time2 | cut -c 3-4`&lt;BR /&gt;&lt;BR /&gt;echo "${typ},${y1}-${m1}-${d1} ${h1}:${mm1},${y2}-${m2}-${d2} ${h2}:${mm2}"&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Hope this helps.. it is not most elegant but easy to follow...</description>
      <pubDate>Thu, 11 Jun 2009 13:33:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/field-format/m-p/4437628#M661176</guid>
      <dc:creator>Mel Burslan</dc:creator>
      <dc:date>2009-06-11T13:33:39Z</dc:date>
    </item>
    <item>
      <title>Re: field format</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/field-format/m-p/4437629#M661177</link>
      <description>Hi Rich, &lt;BR /&gt;Thanks for the hint.&lt;BR /&gt;Hi Mel, &lt;BR /&gt;I have around 1000 records in the file. So opening up a new variable for each record is impossible. &lt;BR /&gt;&lt;BR /&gt;Please suggest something quick as i have 1000 records in the file.</description>
      <pubDate>Thu, 11 Jun 2009 13:35:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/field-format/m-p/4437629#M661177</guid>
      <dc:creator>viseshu</dc:creator>
      <dc:date>2009-06-11T13:35:34Z</dc:date>
    </item>
    <item>
      <title>Re: field format</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/field-format/m-p/4437630#M661178</link>
      <description>you do not have to open up 1000s of valiables for each line. The while loop will go line-by-line to give you the output you need. all the variables defined are for one line. Regardless how many lines you have, you can run this script to print them out in the format specified.</description>
      <pubDate>Thu, 11 Jun 2009 13:38:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/field-format/m-p/4437630#M661178</guid>
      <dc:creator>Mel Burslan</dc:creator>
      <dc:date>2009-06-11T13:38:12Z</dc:date>
    </item>
    <item>
      <title>Re: field format</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/field-format/m-p/4437631#M661179</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;# awk -F"," 'BEGIN{OFS=","};{print $2,substr($3,1,4)"-"substr($3,5,2)"-"substr($3,7,2),substr($5,1,2)":"substr($5,3,2),substr($4,1,4)"-"substr($4,5,2)"-"substr($3,7,2),substr($6,1,2)":"substr($6,3,2)}' file&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 11 Jun 2009 13:38:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/field-format/m-p/4437631#M661179</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-06-11T13:38:47Z</dc:date>
    </item>
    <item>
      <title>Re: field format</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/field-format/m-p/4437632#M661180</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;Oops, you want commas only at selected points, so:&lt;BR /&gt;&lt;BR /&gt;# awk -F, {print $2","substr($3,1,4)"-"substr($3,5,2)"-"substr($3,7,2),substr($5,1,2)":"substr($5,3,2)","substr($4,1,4)"-"substr($4,5,2)"-"substr($3,7,2),substr($6,1,2)":"substr($6,3,2)} file&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 11 Jun 2009 13:42:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/field-format/m-p/4437632#M661180</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-06-11T13:42:52Z</dc:date>
    </item>
    <item>
      <title>Re: field format</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/field-format/m-p/4437633#M661181</link>
      <description>Hi James, &lt;BR /&gt;that was splendid!&lt;BR /&gt;i have few more fields after the time stamp like, &lt;BR /&gt;&lt;BR /&gt;1,type1,20090510,20090511,1000,1100,D,34.0,,,MI&lt;BR /&gt;2,type2,20090611,20090714,1200,1300,,D,78.0,,,KI&lt;BR /&gt;3,type3,20090414,20090515,1600,1700,,K,90.8,,LI&lt;BR /&gt;How do i accomodate if the fields are more. &lt;BR /&gt;&lt;BR /&gt;Thanks in advance.&lt;BR /&gt;</description>
      <pubDate>Thu, 11 Jun 2009 13:43:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/field-format/m-p/4437633#M661181</guid>
      <dc:creator>viseshu</dc:creator>
      <dc:date>2009-06-11T13:43:37Z</dc:date>
    </item>
    <item>
      <title>Re: field format</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/field-format/m-p/4437634#M661182</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; I have few more fields after the time stamp ...How do i accomodate if the fields are more.&lt;BR /&gt;&lt;BR /&gt;You simply reference fields in'awk' as $0 (for the whole line) and $1..$199 for the first through the 199th field.  Awk automatically splits a line into fields based on the record seperator.  For commandline scripts you can use the '-F' switch like I did to designate it.  The manpages offer an overview of functions like 'substr()' which we used to dissect fixed spans of various fields.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt; &lt;BR /&gt;</description>
      <pubDate>Thu, 11 Jun 2009 13:53:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/field-format/m-p/4437634#M661182</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-06-11T13:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: field format</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/field-format/m-p/4437635#M661183</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;to get the rest of the fields unchanged in your output, use&lt;BR /&gt;# awk -F, '{printf("%s,%s-%s-%s %s:%s, %s-%s-%s %s:%s",&lt;BR /&gt;$2,substr($3,1,4),substr($3,5,2),substr($3,7,2),&lt;BR /&gt;substr($5,1,2),substr($5,3,2),&lt;BR /&gt;substr($4,1,4),substr($4,5,2),substr($3,7,2),&lt;BR /&gt;substr($6,1,2),substr($6,3,2));&lt;BR /&gt;for(i=7;i&amp;lt;=NF;i++) printf(",%s",$i); printf("\n")}' file&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
      <pubDate>Fri, 12 Jun 2009 06:31:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/field-format/m-p/4437635#M661183</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2009-06-12T06:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: field format</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/field-format/m-p/4437636#M661184</link>
      <description>tl=5&lt;BR /&gt;for j in `cat /tmp/inp_file`&lt;BR /&gt;do&lt;BR /&gt;        i=1&lt;BR /&gt;        while [ $i -le $tl ]&lt;BR /&gt;        do&lt;BR /&gt;                case $i in&lt;BR /&gt;                1 ) f1=`echo $j | cut -c 3- | cut -f 1 -d ","` ;;&lt;BR /&gt;                2 ) f2=`echo $j | cut -c 3- | cut -f 2 -d ","`&lt;BR /&gt;                        y=`echo $f2 | cut -c -4`&lt;BR /&gt;                        m=`echo $f2 | cut -c 5-6`&lt;BR /&gt;                        d=`echo $f2 | cut -c 7-`&lt;BR /&gt;                        f2=`echo $y-$m-$d`&lt;BR /&gt;                        ;;&lt;BR /&gt;                3 ) f3=`echo $j | cut -c 3- | cut -f 3 -d ","`&lt;BR /&gt;                        y=`echo $f3 | cut -c -4`&lt;BR /&gt;                        m=`echo $f3 | cut -c 5-6`&lt;BR /&gt;                        d=`echo $f3 | cut -c 7-`&lt;BR /&gt;                        f3=`echo $y-$m-$d`&lt;BR /&gt;                        ;;&lt;BR /&gt;                4 ) f4=`echo $j | cut -c 3- | cut -f 4 -d ","`&lt;BR /&gt;                        fs=`echo $f4 | cut -c -2`&lt;BR /&gt;                        ss=`echo $f4 | cut -c 3-`&lt;BR /&gt;                        f4=`echo $fs:$ss`&lt;BR /&gt;                        ;;&lt;BR /&gt;                5 ) f5=`echo $j | cut -c 3- | cut -f 5 -d ","`&lt;BR /&gt;                        fs=`echo $f5 | cut -c -2`&lt;BR /&gt;                        ss=`echo $f5 | cut -c 3-`&lt;BR /&gt;                        f5=`echo $fs:$ss`&lt;BR /&gt;                        ;;&lt;BR /&gt;                esac&lt;BR /&gt;                i=`expr $i + 1`&lt;BR /&gt;        done&lt;BR /&gt;echo "$f1 $f2 $f3 $f4 $f5"&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;HTH</description>
      <pubDate>Thu, 18 Jun 2009 10:38:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/field-format/m-p/4437636#M661184</guid>
      <dc:creator>PING_6</dc:creator>
      <dc:date>2009-06-18T10:38:11Z</dc:date>
    </item>
  </channel>
</rss>

