<?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: generalizing fields for Awk in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/generalizing-fields-for-awk/m-p/3364640#M867124</link>
    <description>We can do this as,&lt;BR /&gt;&lt;BR /&gt;echo "a,b,c,d,e,f,g,h,i,j,k,l,i,j,k,l" | awk -F , '{ printf $1"-"&lt;BR /&gt;&amp;gt; for ( i=2; i&lt;NF&gt;&lt;/NF&gt;&amp;gt; printf $i ","&lt;BR /&gt;&amp;gt; } END { printf $NF }'&lt;BR /&gt;&lt;BR /&gt;output:&lt;BR /&gt;a-b,c,d,e,f,g,h,i,j,k,l,i,j,k,l&lt;BR /&gt;&lt;BR /&gt;Or just easy as,&lt;BR /&gt;echo "a,b,c,d,e,f,g,h,i,j,k,l,i,j,k,l" | sed -e 's/,/-/1'&lt;BR /&gt;&lt;BR /&gt;It will change first occurence of , and change it to - &lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;Muthu</description>
    <pubDate>Wed, 25 Aug 2004 09:17:44 GMT</pubDate>
    <dc:creator>Muthukumar_5</dc:creator>
    <dc:date>2004-08-25T09:17:44Z</dc:date>
    <item>
      <title>generalizing fields for Awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/generalizing-fields-for-awk/m-p/3364635#M867119</link>
      <description>Hi,&lt;BR /&gt;  I have a file that has about 16 columns delimited by comma(","). I need to append only the first two columns by hyphen("-"). For that I am doing some thing like below&lt;BR /&gt;&lt;BR /&gt;awk -F, 'OFS=","{print $1"-"$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16}' my_file&lt;BR /&gt;&lt;BR /&gt;Is there any way of generalising the columns from 3 to 16??&lt;BR /&gt;&lt;BR /&gt;I am expecting some thing like&lt;BR /&gt;awk -F, 'OFS=","{print $1"-"$2,$3-$16}' my_file&lt;BR /&gt;&lt;BR /&gt;Is this possible?&lt;BR /&gt;&lt;BR /&gt;Please kindly help.&lt;BR /&gt;Thanks and Regards,&lt;BR /&gt;-Parmy</description>
      <pubDate>Wed, 25 Aug 2004 08:09:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/generalizing-fields-for-awk/m-p/3364635#M867119</guid>
      <dc:creator>parmy_4</dc:creator>
      <dc:date>2004-08-25T08:09:19Z</dc:date>
    </item>
    <item>
      <title>Re: generalizing fields for Awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/generalizing-fields-for-awk/m-p/3364636#M867120</link>
      <description>Not in awk, you have to use a for loop, eg: -&lt;BR /&gt;&lt;BR /&gt;awk '{ printf $1"-" ; for(i=2; i&amp;lt;=NF; i++) { printf ","$i } ; printf "\n" }' my_file</description>
      <pubDate>Wed, 25 Aug 2004 08:19:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/generalizing-fields-for-awk/m-p/3364636#M867120</guid>
      <dc:creator>Simon Hargrave</dc:creator>
      <dc:date>2004-08-25T08:19:41Z</dc:date>
    </item>
    <item>
      <title>Re: generalizing fields for Awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/generalizing-fields-for-awk/m-p/3364637#M867121</link>
      <description>You could just print $1, that hyphen, and then the substring from the line ($0) starting after $1 and the space.&lt;BR /&gt;&lt;BR /&gt;awk '{ print $1 "-" substr($0,length($1)+2) }' my_file&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Wed, 25 Aug 2004 08:23:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/generalizing-fields-for-awk/m-p/3364637#M867121</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-08-25T08:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: generalizing fields for Awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/generalizing-fields-for-awk/m-p/3364638#M867122</link>
      <description>How about using perl and just replace the first "," with a "-".&lt;BR /&gt; &lt;BR /&gt;perl -p -e 's/,/-/' my_file&lt;BR /&gt; &lt;BR /&gt;HTH&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Wed, 25 Aug 2004 08:40:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/generalizing-fields-for-awk/m-p/3364638#M867122</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2004-08-25T08:40:24Z</dc:date>
    </item>
    <item>
      <title>Re: generalizing fields for Awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/generalizing-fields-for-awk/m-p/3364639#M867123</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;you just can use sed command to substitute the 1st comma :&lt;BR /&gt;&lt;BR /&gt;cat &lt;YOURFILE&gt; | sed -e "s/\,/\-/" &amp;gt; &lt;YOURNEWFILE&gt;&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;Jean-Luc&lt;/YOURNEWFILE&gt;&lt;/YOURFILE&gt;</description>
      <pubDate>Wed, 25 Aug 2004 08:53:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/generalizing-fields-for-awk/m-p/3364639#M867123</guid>
      <dc:creator>Jean-Luc Oudart</dc:creator>
      <dc:date>2004-08-25T08:53:34Z</dc:date>
    </item>
    <item>
      <title>Re: generalizing fields for Awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/generalizing-fields-for-awk/m-p/3364640#M867124</link>
      <description>We can do this as,&lt;BR /&gt;&lt;BR /&gt;echo "a,b,c,d,e,f,g,h,i,j,k,l,i,j,k,l" | awk -F , '{ printf $1"-"&lt;BR /&gt;&amp;gt; for ( i=2; i&lt;NF&gt;&lt;/NF&gt;&amp;gt; printf $i ","&lt;BR /&gt;&amp;gt; } END { printf $NF }'&lt;BR /&gt;&lt;BR /&gt;output:&lt;BR /&gt;a-b,c,d,e,f,g,h,i,j,k,l,i,j,k,l&lt;BR /&gt;&lt;BR /&gt;Or just easy as,&lt;BR /&gt;echo "a,b,c,d,e,f,g,h,i,j,k,l,i,j,k,l" | sed -e 's/,/-/1'&lt;BR /&gt;&lt;BR /&gt;It will change first occurence of , and change it to - &lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;Muthu</description>
      <pubDate>Wed, 25 Aug 2004 09:17:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/generalizing-fields-for-awk/m-p/3364640#M867124</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-08-25T09:17:44Z</dc:date>
    </item>
    <item>
      <title>Re: generalizing fields for Awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/generalizing-fields-for-awk/m-p/3364641#M867125</link>
      <description>no there isn't any syntax for specifing a range of fields within awk.&lt;BR /&gt;&lt;BR /&gt;but if your data is already comma delimited,&lt;BR /&gt;all you need to do is change the first comma&lt;BR /&gt;&lt;BR /&gt;awk '{sub(",","-");print $0;}'&lt;BR /&gt;&lt;BR /&gt;or using sed&lt;BR /&gt;&lt;BR /&gt;sed -e 's/,/-/'&lt;BR /&gt;&lt;BR /&gt;and you already have a perl example&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 25 Aug 2004 11:40:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/generalizing-fields-for-awk/m-p/3364641#M867125</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2004-08-25T11:40:48Z</dc:date>
    </item>
    <item>
      <title>Re: generalizing fields for Awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/generalizing-fields-for-awk/m-p/3364642#M867126</link>
      <description>Guys,&lt;BR /&gt;  Thanks a lot for your time helping me to know about generalising. I am impressed by all your replies and thanks again.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Parmy</description>
      <pubDate>Thu, 26 Aug 2004 05:38:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/generalizing-fields-for-awk/m-p/3364642#M867126</guid>
      <dc:creator>parmy_4</dc:creator>
      <dc:date>2004-08-26T05:38:22Z</dc:date>
    </item>
  </channel>
</rss>

