The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
select a record from one file matching from second file using awk synmag Shell Programming and Scripting 7 06-11-2008 11:37 PM
select a portion of a file into a CSV anju Shell Programming and Scripting 8 02-27-2008 10:50 PM
Select last block from a file misenkiser Shell Programming and Scripting 9 10-11-2006 06:32 AM
select distinct row from a file merry susana UNIX for Dummies Questions & Answers 7 05-03-2005 03:54 AM
select datas from an input file dde Shell Programming and Scripting 1 05-21-2002 08:02 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 11-14-2006
Registered User
 

Join Date: Sep 2006
Posts: 10
select last field from a file

hi everybody

i would to select the last field of a file
here as you can see i select the field number 8

y=`cat sortie2 | grep "^[1-9999]"| grep "starting"| awk '{ print $8}'`

but line can containt more or less field in never know, i just know is the last one

so i wondering to know if is something like
y=`cat sortie2 | grep "^[1-9999]"| grep "starting"| awk '{ print $lastfield}'`

or a other solution
thank a lot
Reply With Quote
Forum Sponsor
  #2  
Old 11-14-2006
Registered User
 

Join Date: Jan 2006
Posts: 24
y=`cat sortie2 | grep "^[1-9999]"| grep "starting"| awk '{ print $NF}'
Reply With Quote
  #3  
Old 11-14-2006
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,212
I'm not sure that the command "grep" is doing what you want.
This command selects lines starting with a digit (from 1 to 9).

If you want to select lines with field 1 between 1 and 9999, you can do:
Code:
y=`awk '$1 > 1 && $1 <9999 && /starting/ { print $NF }' sortie2`
Jean-Pierre.
Reply With Quote
  #4  
Old 11-14-2006
Registered User
 

Join Date: Sep 2006
Posts: 10
thank a lot that works
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:33 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0