<?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: Extracting the last field in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/extracting-the-last-field/m-p/3915055#M96945</link>
    <description>Henry,&lt;BR /&gt;assuming that there are no souble-spaces:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;while read record&lt;BR /&gt;do&lt;BR /&gt;# Count the number of words&lt;BR /&gt;max=`echo "$record" | wc -w `&lt;BR /&gt;# Get that last field&lt;BR /&gt;echo "$record" | cut -d' ' -f $max&lt;BR /&gt;done &amp;lt; a.lis</description>
    <pubDate>Tue, 19 Dec 2006 04:04:16 GMT</pubDate>
    <dc:creator>Peter Godron</dc:creator>
    <dc:date>2006-12-19T04:04:16Z</dc:date>
    <item>
      <title>Extracting the last field</title>
      <link>https://community.hpe.com/t5/operating-system-linux/extracting-the-last-field/m-p/3915054#M96944</link>
      <description>Hi guys,&lt;BR /&gt;&lt;BR /&gt;  I have a big datafile and will like to extract the last field of each line i.e. if i have a string "Field1 Field2 Field3 .." how can i extract the last field if the number of field is unknown using perl?&lt;BR /&gt;&lt;BR /&gt;Best regards&lt;BR /&gt;Henry</description>
      <pubDate>Tue, 19 Dec 2006 02:32:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/extracting-the-last-field/m-p/3915054#M96944</guid>
      <dc:creator>Henry Chua</dc:creator>
      <dc:date>2006-12-19T02:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting the last field</title>
      <link>https://community.hpe.com/t5/operating-system-linux/extracting-the-last-field/m-p/3915055#M96945</link>
      <description>Henry,&lt;BR /&gt;assuming that there are no souble-spaces:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;while read record&lt;BR /&gt;do&lt;BR /&gt;# Count the number of words&lt;BR /&gt;max=`echo "$record" | wc -w `&lt;BR /&gt;# Get that last field&lt;BR /&gt;echo "$record" | cut -d' ' -f $max&lt;BR /&gt;done &amp;lt; a.lis</description>
      <pubDate>Tue, 19 Dec 2006 04:04:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/extracting-the-last-field/m-p/3915055#M96945</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2006-12-19T04:04:16Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting the last field</title>
      <link>https://community.hpe.com/t5/operating-system-linux/extracting-the-last-field/m-p/3915056#M96946</link>
      <description>&lt;!--!*#--&gt;For awk you can use:&lt;BR /&gt;   awk '{print $NF}'</description>
      <pubDate>Tue, 19 Dec 2006 04:42:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/extracting-the-last-field/m-p/3915056#M96946</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2006-12-19T04:42:16Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting the last field</title>
      <link>https://community.hpe.com/t5/operating-system-linux/extracting-the-last-field/m-p/3915057#M96947</link>
      <description>Hey&lt;BR /&gt;&lt;BR /&gt;u can use:&lt;BR /&gt;&lt;BR /&gt;echo a b c | perl -lane 'print "@F[-1]"'&lt;BR /&gt;&lt;BR /&gt;returns c&lt;BR /&gt;&lt;BR /&gt;use instead of echo a b c, cat filename&lt;BR /&gt;&lt;BR /&gt;Regards</description>
      <pubDate>Tue, 19 Dec 2006 04:59:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/extracting-the-last-field/m-p/3915057#M96947</guid>
      <dc:creator>Oviwan</dc:creator>
      <dc:date>2006-12-19T04:59:29Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting the last field</title>
      <link>https://community.hpe.com/t5/operating-system-linux/extracting-the-last-field/m-p/3915058#M96948</link>
      <description>Thanks Oviwan,&lt;BR /&gt;&lt;BR /&gt;May I know how can i implement for a loop in a script. Example to print the last field for a file i am reading:&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;foreach $line (&lt;DATAFILE&gt;) {&lt;BR /&gt; #print last field of the textfile&lt;BR /&gt;}&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;Thanks in advance. &lt;BR /&gt;&lt;BR /&gt;Best regards&lt;BR /&gt;Henry&lt;BR /&gt;&lt;/DATAFILE&gt;</description>
      <pubDate>Tue, 19 Dec 2006 05:35:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/extracting-the-last-field/m-p/3915058#M96948</guid>
      <dc:creator>Henry Chua</dc:creator>
      <dc:date>2006-12-19T05:35:01Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting the last field</title>
      <link>https://community.hpe.com/t5/operating-system-linux/extracting-the-last-field/m-p/3915059#M96949</link>
      <description>Try this &lt;BR /&gt;&lt;BR /&gt;open(FILE,"&amp;lt;","filename");&lt;BR /&gt;&lt;BR /&gt;while (&lt;FILE&gt;) {&lt;BR /&gt;   @fields=split(/\ /,$_); #split spaces&lt;BR /&gt;   print $fields[$#fields];&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Regards&lt;/FILE&gt;</description>
      <pubDate>Tue, 19 Dec 2006 06:01:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/extracting-the-last-field/m-p/3915059#M96949</guid>
      <dc:creator>Oviwan</dc:creator>
      <dc:date>2006-12-19T06:01:48Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting the last field</title>
      <link>https://community.hpe.com/t5/operating-system-linux/extracting-the-last-field/m-p/3915060#M96950</link>
      <description>Hi Henry:&lt;BR /&gt;&lt;BR /&gt;To print the last field of a file:&lt;BR /&gt;&lt;BR /&gt;# perl -nale 'print $F[$#F]' filename&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 19 Dec 2006 07:15:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/extracting-the-last-field/m-p/3915060#M96950</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-12-19T07:15:58Z</dc:date>
    </item>
  </channel>
</rss>

