select last field from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting select last field from a file
# 1  
Old 11-14-2006
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
# 2  
Old 11-14-2006
y=`cat sortie2 | grep "^[1-9999]"| grep "starting"| awk '{ print $NF}'
# 3  
Old 11-14-2006
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.
# 4  
Old 11-14-2006
thank a lot that works
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Select only the lines of a file starting with a field which is matcing a list. awk?

Hello I have a large file1 which has many events like "2014010420" and following lines under each event that start with text . It has this form: 2014010420 num --- --- num .... NTE num num --- num... EFA num num --- num ... LASW num num --- num... (9 Replies)
Discussion started by: phaethon
9 Replies

2. Shell Programming and Scripting

Using awk to select one field

Hi, I saw your post.. I have a dought in awk command... how to get the output from a file. i need a first column in etc/passwd file in a single column (in indivijual line)... i couldn't get with this command cat /etc/passwd | awk -F ":" '{printf $1}' Kindly help This thread was created... (3 Replies)
Discussion started by: Dheepak s
3 Replies

3. Linux

How do I format a Date field of a .CSV file with multiple commas in a string field?

I have a .CSV file (file.csv) whose data are all enclosed in double quotes. Sample format of the file is as below: column1,column2,column3,column4,column5,column6, column7, Column8, Column9, Column10 "12","B000QRIGJ4","4432","string with quotes, and with a comma, and colon: in... (3 Replies)
Discussion started by: dhruuv369
3 Replies

4. Shell Programming and Scripting

How to select a particular field from a drop-down menu in a webpage using perl script?

Hi Team, I have a requirement to login into URL using username and password , then I have to select a "particular name" from drop-down menu and then Read the values user records etc.... using perl. Is it possible to do in perl script ? (OR) Can you please let me know which scripting... (1 Reply)
Discussion started by: latika
1 Replies

5. Programming

Select and group by excluding one field

Dear community, I have a very simple query (on Oracle 11g) to select 3 fields: select field1, field2, field3, count(*) from table where... group by field1, field2, field3 having count(*) > 10;Now, what I need, is exclude "field3" from the "group by" since I only need field 1 and 2 to be... (2 Replies)
Discussion started by: Lord Spectre
2 Replies

6. Shell Programming and Scripting

Append 1st field from a file into 2nd field of another file

Hi, I've internally searched through forums for about 2+ hours. Unfortunately, with no luck. Although I've found some cases close to mine below, but didn't help so much. Actually, I'm in short with time. So I had to post my case. Hoping that you can help. I have 2 files, FILE1 ... (1 Reply)
Discussion started by: amurib
1 Replies

7. Shell Programming and Scripting

Appending 1st field in a file into 2nd field in another file

Hi, I've internally searched through forums for about 2+ hours. Unfortunately, with no luck. Although I've found some cases close to mine below, but didn't help so much. Actually, I'm in short with time. So I had to post my case. Hoping that you can help. I have 2 files, FILE1 ... (0 Replies)
Discussion started by: amurib
0 Replies

8. Shell Programming and Scripting

How to select or make reference to, part of a field

For a field format such as AAL1001_MD82, how do I select(and use in if statement) only the last four elements( in this case MD82) or the first three elements (in this case AAL)? For instance, how do I do the following - if first three elements of $x == yyy, then ... (5 Replies)
Discussion started by: akshaykr2
5 Replies

9. Shell Programming and Scripting

::select statement return value with correct field size::

Hi Everyone, I am facing a problem regarding the select from sybase, the return with the incorrect size. For example, field is NAME(20). After i selected from sybase, the result is nicky. after i assign it to another declaration variable, it will be in actual name "nicky" , what i need... (10 Replies)
Discussion started by: ryanW
10 Replies

10. Shell Programming and Scripting

select a particular field

hi i have a file wwww-qqq.eee ksdklfsdf adm,as.d,am sdsdlasdjl sadsadasda wwww-qqq.eee ksdklfsdf adm,as.d,am sdsdlasdjl sadsadasda wwww-qqq.eee ksdklfsdf adm,as.d,am sdsdlasdjl sadsadasda wwww-qqq.eee ksdklfsdf adm,as.d,am sdsdlasdjl sadsadasda wwww-qqq.eee ksdklfsdf adm,as.d,am... (4 Replies)
Discussion started by: Satyak
4 Replies
Login or Register to Ask a Question