From: John Knight Date: 2002-05-30T02:28:38+09:00 Subject: [Fwd: Re: [ma-linux] Seeking the right (most)] I sent this message earlier but it appears not to have been distributed by the list manager. John -------- Original Message -------- Subject: Re: [ma-linux] Seeking the right (most) Date: Wed, 29 May 2002 13:21:02 -0400 From: John Knight CC: ma-linux@tux.org References: <20020527194537.GA2465@tux.org> <20020529124038.A7874@gwyn.tux.org> Hi All, I put the following message on ruby-talk@ruby-lang.org malug is discussing the following question: How to print the rightmost word for every line in ? I tried to introduce ruby to the debate. But am not sure I have the best solution. ruby -ne 'arr=split; puts "#{arr.last}"' #john I less than three hours, I got the following replies: ruby -ne "arr=split; puts arr.last" [file] #Tobi ruby -nae 'puts $F[-1]' You'll get nils in the output for blank lines; depending on what you want to ruby -nae 'puts $F[-1] if $F[-1]' ruby -lane 'puts $F[-1] || ""' # Dossy Much though I like Ruby, I use "awk '{print $NF'}" for that. Clifford Heath ruby -lane 'print $F[-1]' # matz < matz is the creator of ruby.> ruby -ne 'puts split.last' ruby -nae 'puts $F.last' #But it prints 'nil' for empty lines.Mike Hall All this -- including a response from matz. We are in a real learning community. :) My favorite because it is object oriented is: ruby -ne 'puts split.last' matz's version will appeal to awk or perl affectionadoes: ruby -lane 'print $F[-1]' John