<?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 - print range of fields in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055485#M435673</link>
    <description>awk '{ printf("%s %s %s ",$4,$2,$3); i = 6; while (i &amp;lt; (NF - 1)) { printf("%s ",$i); ++i; } printf("%s\n",$NF); }'</description>
    <pubDate>Thu, 28 Jun 2007 10:28:10 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2007-06-28T10:28:10Z</dc:date>
    <item>
      <title>awk - print range of fields</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055484#M435672</link>
      <description>Hello all,&lt;BR /&gt;&lt;BR /&gt;I'm trying to rearrange a file where rows contain a variable number of fields.&lt;BR /&gt;How can I print "field 6 to end of line"?&lt;BR /&gt;&lt;BR /&gt;example:&lt;BR /&gt;awk '{print $4 " " $2 " " $3 " " $6through$NF :'&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;RayB</description>
      <pubDate>Thu, 28 Jun 2007 10:17:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055484#M435672</guid>
      <dc:creator>Raynald Boucher</dc:creator>
      <dc:date>2007-06-28T10:17:04Z</dc:date>
    </item>
    <item>
      <title>Re: awk - print range of fields</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055485#M435673</link>
      <description>awk '{ printf("%s %s %s ",$4,$2,$3); i = 6; while (i &amp;lt; (NF - 1)) { printf("%s ",$i); ++i; } printf("%s\n",$NF); }'</description>
      <pubDate>Thu, 28 Jun 2007 10:28:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055485#M435673</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2007-06-28T10:28:10Z</dc:date>
    </item>
    <item>
      <title>Re: awk - print range of fields</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055486#M435674</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;# awk '{printf "%s %s %s ",$4,$2,$3;for (i=7;i&lt;NF&gt;&lt;/NF&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 28 Jun 2007 10:32:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055486#M435674</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-06-28T10:32:11Z</dc:date>
    </item>
    <item>
      <title>Re: awk - print range of fields</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055487#M435675</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;Ooops!  Initialize i=6 not i=7...&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 28 Jun 2007 10:33:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055487#M435675</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-06-28T10:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: awk - print range of fields</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055488#M435676</link>
      <description>&lt;!--!*#--&gt;awk '{&lt;BR /&gt;  for(i=2;i&amp;lt;=NF;++i) {&lt;BR /&gt;    if (i==2)&lt;BR /&gt;      str=$i&lt;BR /&gt;    else if (i==3)&lt;BR /&gt;      str=str" "$i&lt;BR /&gt;    else if(i==4)&lt;BR /&gt;      str=$i" "str&lt;BR /&gt;    else if (i==5)&lt;BR /&gt;      printf("%s ",str)&lt;BR /&gt;    else&lt;BR /&gt;      printf(i&lt;NF&gt;&lt;/NF&gt;  }&lt;BR /&gt;}' infile&lt;BR /&gt;</description>
      <pubDate>Thu, 28 Jun 2007 10:44:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055488#M435676</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-06-28T10:44:32Z</dc:date>
    </item>
    <item>
      <title>Re: awk - print range of fields</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055489#M435677</link>
      <description>In perl you can take a slice of an array with the x .. y notation.&lt;BR /&gt;The elements start at 0&lt;BR /&gt;A little to my surprise i coudl not use [5..-1] to indicate a slice from the 6th fields thru  the end.&lt;BR /&gt;&lt;BR /&gt;Anyway... a perl solution:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;perl -alpe '$_ = join " ",@F[3,1,2,5..@F-1]' x.tmp&lt;BR /&gt;&lt;BR /&gt;-a = autosplit into array @F&lt;BR /&gt;-l = add newline to print&lt;BR /&gt;-p = print $_ before looping &lt;BR /&gt;-e = here comes the program&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 28 Jun 2007 11:13:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055489#M435677</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-06-28T11:13:23Z</dc:date>
    </item>
    <item>
      <title>Re: awk - print range of fields</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055490#M435678</link>
      <description>Thanks all,&lt;BR /&gt;I had never thought of the loop.&lt;BR /&gt;&lt;BR /&gt;I'll have to get a book or at least a quick ref.&lt;BR /&gt;&lt;BR /&gt;Thanks again.&lt;BR /&gt;Rayb</description>
      <pubDate>Thu, 28 Jun 2007 12:09:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055490#M435678</guid>
      <dc:creator>Raynald Boucher</dc:creator>
      <dc:date>2007-06-28T12:09:43Z</dc:date>
    </item>
    <item>
      <title>Re: awk - print range of fields</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055491#M435679</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; Hein: A little to my surprise i coudl not use [5..-1] to indicate a slice from the 6th fields thru the end.&lt;BR /&gt;&lt;BR /&gt;Yes, but this would work:&lt;BR /&gt;&lt;BR /&gt;# perl -alpe '$_ = join " ",@F[3,1,2,-4..-1]' x.tmp&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 28 Jun 2007 12:16:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055491#M435679</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-06-28T12:16:01Z</dc:date>
    </item>
    <item>
      <title>Re: awk - print range of fields</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055492#M435680</link>
      <description>Ray,&lt;BR /&gt;&lt;BR /&gt;Sorry for this side line&lt;BR /&gt;&lt;BR /&gt;And btw... &lt;BR /&gt;why not just TRY the perl solution.&lt;BR /&gt;It's just an other language/tool.&lt;BR /&gt;&lt;BR /&gt;JRF,&lt;BR /&gt;&amp;gt;&amp;gt; # perl -alpe '$_ = join " ",@F[3,1,2,-4..-1]' x.tmp&lt;BR /&gt;&lt;BR /&gt;Yes, the -n..-m does work but the start end end of the slice would both be relative to the end. So for example for 20 fields it would return 16 .. 20, not the desired 6 .. 20.&lt;BR /&gt;&lt;BR /&gt;fwiw,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Thu, 28 Jun 2007 12:25:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055492#M435680</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-06-28T12:25:18Z</dc:date>
    </item>
    <item>
      <title>Re: awk - print range of fields</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055493#M435681</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;Hein: &amp;gt; Yes, the -n..-m does work but the start end end of the slice would both be relative to the end. So for example for 20 fields it would return 16 .. 20, not the desired 6 .. 20.&lt;BR /&gt;&lt;BR /&gt;Yes, I now see why you chose the approach you did.&lt;BR /&gt;&lt;BR /&gt;Sandman: BTW, I had not thought of using conditional operators in 'awk'.  That's very nice!&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 28 Jun 2007 12:32:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055493#M435681</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-06-28T12:32:00Z</dc:date>
    </item>
    <item>
      <title>Re: awk - print range of fields</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055494#M435682</link>
      <description>Hein and James,&lt;BR /&gt;&lt;BR /&gt;Sometimes I'd like to try Perl but We don't use it except in some OS scripts and noboby in my shop is proficient.&lt;BR /&gt;It would become a maintenance problem.&lt;BR /&gt;&lt;BR /&gt;Is there a -quick- way to learn Perl?&lt;BR /&gt;Which manual would you recommend?&lt;BR /&gt;&lt;BR /&gt;Rayb</description>
      <pubDate>Thu, 28 Jun 2007 12:47:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055494#M435682</guid>
      <dc:creator>Raynald Boucher</dc:creator>
      <dc:date>2007-06-28T12:47:20Z</dc:date>
    </item>
    <item>
      <title>Re: awk - print range of fields</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055495#M435683</link>
      <description>Hi Raynald:&lt;BR /&gt;&lt;BR /&gt;I'd probably start with "Learning Perl" from the O'Reilly publishers.  A compendium of links to good stuff is:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://perlmonks.org/index.pl?node_id=284175" target="_blank"&gt;http://perlmonks.org/index.pl?node_id=284175&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Like any language, the best way to really learn it is to use it.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 28 Jun 2007 13:03:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055495#M435683</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-06-28T13:03:15Z</dc:date>
    </item>
    <item>
      <title>Re: awk - print range of fields</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055496#M435684</link>
      <description>The learning curve for Perl is a bit steeper than with many other scripting languages but the rewards are also greater. It's one of the very few scripting languages that are widely portable. Well-written Perl scripts will run on any flavor of UNIX, Windows, MacOS, VMS, ...  without change. Unlike most scripting languages, almost anything that can be done in C can also be done in Perl.&lt;BR /&gt;&lt;BR /&gt;Perhaps the worst quality of Perl is also its best quality: the ability to pack an enormous amount of processing into one line. This characteristic makes it very easy to produce Perl code that is extremely cryptic especially for beginners. It's really quite easy to write Perl in a style that is verbose and clear; it's just not done that often. I suppose that it's one of those "suffering (or at least confusion) is good for the soul" things.</description>
      <pubDate>Thu, 28 Jun 2007 13:59:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055496#M435684</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2007-06-28T13:59:23Z</dc:date>
    </item>
    <item>
      <title>Re: awk - print range of fields</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055497#M435685</link>
      <description>&lt;BR /&gt;&lt;BR /&gt;Btw... if the contents of field $6 van not match fields $1 - $5, then a simple awk solution could be:&lt;BR /&gt;&lt;BR /&gt;$ awk '{print $4,$2,$3,substr($0,index($0,$6))}' x.tmp&lt;BR /&gt;&lt;BR /&gt;If $6 is a 'short' field then you can increase its uniqueness by pre end-or post pending a knwo separator:&lt;BR /&gt;&lt;BR /&gt;$ awk '{print $4,$2,$3,substr($0,index($0," " $6 " "))}' x.tmp&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Thu, 28 Jun 2007 14:23:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055497#M435685</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-06-28T14:23:47Z</dc:date>
    </item>
    <item>
      <title>Re: awk - print range of fields</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055498#M435686</link>
      <description>Maybe a better tools then awk would be "cut".&lt;BR /&gt; &lt;BR /&gt;cut -f 4,2,3,6- inputfile &amp;gt;outputfile&lt;BR /&gt; &lt;BR /&gt;cut assumes tab for the delimiter, but you can override with the -d option.&lt;BR /&gt; &lt;BR /&gt;HTH&lt;BR /&gt; &lt;BR /&gt;Rod Hills</description>
      <pubDate>Thu, 28 Jun 2007 16:04:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055498#M435686</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2007-06-28T16:04:44Z</dc:date>
    </item>
    <item>
      <title>Re: awk - print range of fields</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055499#M435687</link>
      <description>&amp;gt;Rod: Maybe a better tools then awk would be "cut".&lt;BR /&gt;&lt;BR /&gt;cut(1) is usually not a better tool than awk.  &lt;BR /&gt;It has rigorous ideas of delimiters, if you have more than one between fields.</description>
      <pubDate>Thu, 28 Jun 2007 22:36:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055499#M435687</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-06-28T22:36:18Z</dc:date>
    </item>
    <item>
      <title>Re: awk - print range of fields</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055500#M435688</link>
      <description>Thanks again, closing thread.</description>
      <pubDate>Fri, 29 Jun 2007 07:44:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055500#M435688</guid>
      <dc:creator>Raynald Boucher</dc:creator>
      <dc:date>2007-06-29T07:44:58Z</dc:date>
    </item>
    <item>
      <title>Re: awk - print range of fields</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055501#M435689</link>
      <description>Closed!</description>
      <pubDate>Fri, 29 Jun 2007 07:48:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-range-of-fields/m-p/5055501#M435689</guid>
      <dc:creator>Raynald Boucher</dc:creator>
      <dc:date>2007-06-29T07:48:48Z</dc:date>
    </item>
  </channel>
</rss>

