<?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: Unix Scripting in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/unix-scripting/m-p/3236077#M172893</link>
    <description>cat yourfile | &lt;BR /&gt;awk '&lt;BR /&gt;/^cp/ {print;next;}&lt;BR /&gt;/aud/ {printf("%s-%s-%s,%.1f, %s\n",$2,$1,substr($3,3),$5,$6);}'</description>
    <pubDate>Wed, 31 Mar 2004 21:02:04 GMT</pubDate>
    <dc:creator>curt larson_1</dc:creator>
    <dc:date>2004-03-31T21:02:04Z</dc:date>
    <item>
      <title>Unix Scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/unix-scripting/m-p/3236075#M172891</link>
      <description>Hi, &lt;BR /&gt;I have the following unix file which I would like to reformat it into a csv file as per the attachement.&lt;BR /&gt;&lt;BR /&gt;Any ideas would be appreciated.&lt;BR /&gt;&lt;BR /&gt;Password: &lt;BR /&gt; cpi_quarter                cpi                  face_currency &lt;BR /&gt; -------------------------- -------------------- ------------- &lt;BR /&gt;        Dec  1 2002 12:00AM           139.500000 aud           &lt;BR /&gt;        Mar  1 2003 12:00AM           141.300000 aud           &lt;BR /&gt;        Jun  1 2003 12:00AM           141.300000 aud           &lt;BR /&gt;        Sep  1 2003 12:00AM           142.100000 aud           &lt;BR /&gt;&lt;BR /&gt;(return status = 0)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Oktay</description>
      <pubDate>Wed, 31 Mar 2004 18:55:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/unix-scripting/m-p/3236075#M172891</guid>
      <dc:creator>Oktay Tasdemir</dc:creator>
      <dc:date>2004-03-31T18:55:20Z</dc:date>
    </item>
    <item>
      <title>Re: Unix Scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/unix-scripting/m-p/3236076#M172892</link>
      <description>SMOP:&lt;BR /&gt;&lt;BR /&gt;perl -n to-csv.pl &amp;lt; raw-data.dat &amp;gt; data.csv&lt;BR /&gt;&lt;BR /&gt;where to-csv.pl is:&lt;BR /&gt;&lt;BR /&gt;print "$1,$2,$3\n" if (/^(\w+)\s(\w+)\s(\w+)$/) ;&lt;BR /&gt;if (/^(\w{3})\s+(\d+)\s+20(\d\d).*\s(\d+\.\d+)\s+(\w+)/) {&lt;BR /&gt; printf ("%s-%s-%s,%.1f, %s\n",$2,$1,$3,0+$4,$5);&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Ugly reg-expr, but not too hard.&lt;BR /&gt;&lt;BR /&gt;first: find a line starting with (^) a word, and other word and a final ($) word, remembering each word ().&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Next, find lines startign with ^ a 3 char word (remember it in $1), whitespace, 1-or-more decimals (the day, remembered in $2), whitespace and 20 followed immediatly by two decimals (the year, remembers in $3)&lt;BR /&gt;and so on...&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Wed, 31 Mar 2004 20:08:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/unix-scripting/m-p/3236076#M172892</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-03-31T20:08:16Z</dc:date>
    </item>
    <item>
      <title>Re: Unix Scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/unix-scripting/m-p/3236077#M172893</link>
      <description>cat yourfile | &lt;BR /&gt;awk '&lt;BR /&gt;/^cp/ {print;next;}&lt;BR /&gt;/aud/ {printf("%s-%s-%s,%.1f, %s\n",$2,$1,substr($3,3),$5,$6);}'</description>
      <pubDate>Wed, 31 Mar 2004 21:02:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/unix-scripting/m-p/3236077#M172893</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2004-03-31T21:02:04Z</dc:date>
    </item>
    <item>
      <title>Re: Unix Scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/unix-scripting/m-p/3236078#M172894</link>
      <description>Thanks for the replies,&lt;BR /&gt;&lt;BR /&gt;I have gone with Curt's solution as it looked somewhat easier.&lt;BR /&gt;The output that was produced was&lt;BR /&gt;&lt;BR /&gt;1-Dec-02,139.5, aud&lt;BR /&gt;1-Mar-03,141.3, aud&lt;BR /&gt;1-Jun-03,141.3, aud&lt;BR /&gt;1-Sep-03,142.1, aud&lt;BR /&gt;&lt;BR /&gt;I also require the headings as per below&lt;BR /&gt;&lt;BR /&gt;cpi_quarter,cpi,face_currency&lt;BR /&gt;1-Dec-02,139.5, aud&lt;BR /&gt;1-Mar-03,141.3, aud&lt;BR /&gt;1-Jun-03,141.3, aud&lt;BR /&gt;1-Sep-03,142.1, aud&lt;BR /&gt;&lt;BR /&gt;Would you be able to explain the awk script as then I might be able to figure it out.&lt;BR /&gt;&lt;BR /&gt;Many thanks</description>
      <pubDate>Thu, 01 Apr 2004 00:36:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/unix-scripting/m-p/3236078#M172894</guid>
      <dc:creator>Oktay Tasdemir</dc:creator>
      <dc:date>2004-04-01T00:36:08Z</dc:date>
    </item>
    <item>
      <title>Re: Unix Scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/unix-scripting/m-p/3236079#M172895</link>
      <description>My reply was a bit overly 'excessively protective.&lt;BR /&gt;&lt;BR /&gt;Curt's a little under protective because it does not handle a day-in-the-month in other then 1-9 and only does one currency (aud).&lt;BR /&gt;It also fails to comma seperate the header.&lt;BR /&gt;Easily fixed:&lt;BR /&gt;&lt;BR /&gt;awk 'BEGIN {OFS=","}/^cp/{print $1,$2,$3}&lt;BR /&gt;/[AP]M /{printf("%s-%s-%s,%.1f, %s\n",$2,$1,substr($3,3),$5,$6);}' &amp;lt; yourfile&lt;BR /&gt;cpi_quarter,cpi,face_currency&lt;BR /&gt;1-Dec-02,139.5, aud&lt;BR /&gt;1-Mar-03,141.3, aud&lt;BR /&gt;1-Jun-03,141.3, aud&lt;BR /&gt;1-Sep-03,142.1, aud&lt;BR /&gt;&lt;BR /&gt;Try 'man awk'&lt;BR /&gt;BEGIN = do once, in the beginning&lt;BR /&gt;OFS = output field seperator&lt;BR /&gt;/^cp/ find a line starting (^) with cp&lt;BR /&gt;$1, $2,... input fields seperated by spaces.&lt;BR /&gt;/[AP]M / find a line with "AM " or "PM " anywhere.&lt;BR /&gt;substr ... just pick everything from teh 3rd char in the 3rd field.&lt;BR /&gt;&lt;BR /&gt;For grins a more readable perl version:&lt;BR /&gt;&lt;BR /&gt;x.pl:&lt;BR /&gt;print join (",",split)."\n" if /^cp/;&lt;BR /&gt;if (/[AP]M /) {&lt;BR /&gt;  ($mo,$da,$yr,$ti,$x,$cu)=split;&lt;BR /&gt;  $yr =~ s/20//;&lt;BR /&gt;  printf ("%s-%s-%s,%.1f,%s\n",$da,$mo,$yr,$x,$cu);&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt;perl -n x.pl &amp;lt; yourdata&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 01 Apr 2004 01:07:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/unix-scripting/m-p/3236079#M172895</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-04-01T01:07:01Z</dc:date>
    </item>
  </channel>
</rss>

