Get Nth record from last line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get Nth record from last line
# 1  
Old 05-13-2009
Get Nth record from last line

I have a growing file . I knew only last few lines which is constant for evey job run. I'd need to pull the Nth record from the last line. In this case i should not use search pattern.
# 2  
Old 05-13-2009
One way - assume you want line #101 from the end
Code:
tail -101 filename | head -1

# 3  
Old 05-13-2009
Quote:
Originally Posted by ford2020
I have a growing file . I knew only last few lines which is constant for evey job run. I'd need to pull the Nth record from the last line. In this case i should not use search pattern.
If you want the last line, use:

Code:
tail -n 1

How you pull the record from a specific position depends on how the record is delimited and what tools you have available (sed, awk, Perl, etc.).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing string from last field of the nth line of file to start (or end) of each line (awk I think)

My file (the output of an experiment) starts off looking like this, _____________________________________________________________ Subjects incorporated to date: 001 Data file started on machine PKSHS260-05CP ********************************************************************** Subject 1,... (9 Replies)
Discussion started by: samonl
9 Replies

2. UNIX for Beginners Questions & Answers

Insert a line of text on nth line of a file

Hi All, I am using UNix Sun OS sun4u sparc SUNW,SPARC-Enterprise My intention is to insert a line of text after 13th line of every file inside a particular directory. While trying to do it for a single file , i am using sed sed '3 i this is the 4th line' filename sed: command garbled: 3... (5 Replies)
Discussion started by: gotamp
5 Replies

3. UNIX for Dummies Questions & Answers

Give name for every nth line

Hi all, Greetings. I am facing some troubles and hope that the professionals here could help me. I am handling a large dataset, and part of it is like below: 1 ab139 0 752566 G A 1 ab151 0 846808 T C 1 ab142 0 854250 G A 1 ab061 0 861808 A G 1 ab043 0 873558 T G... (4 Replies)
Discussion started by: Amanda Low
4 Replies

4. Shell Programming and Scripting

Calculating average for every Nth line in the Nth column

Is there an awk script that can easily perform the following operation? I have a data file that is in the format of 1944-12,5.6 1945-01,9.8 1945-02,6.7 1945-03,9.3 1945-04,5.9 1945-05,0.7 1945-06,0.0 1945-07,0.0 1945-08,0.0 1945-09,0.0 1945-10,0.2 1945-11,10.5 1945-12,22.3... (3 Replies)
Discussion started by: ncwxpanther
3 Replies

5. UNIX for Dummies Questions & Answers

how to delete nth line

can you please tell me (1) how to delete 1st and 3rd line only from a file. (2) How to delete last 4 lines in a file that has 2 blank lines out of last 4 lines. Thank you. (2 Replies)
Discussion started by: Ariean
2 Replies

6. Shell Programming and Scripting

How to start reading from the nth line till the last line of a file.

Hi, For my reuirement, I have to read a file from the 2nd line till the last line<EOF>. Say, I have a file as test.txt, which as a header record in the first line followed by records in rest of the lines. for i in `cat test.txt` { echo $i } While doing the above loop, I have read... (5 Replies)
Discussion started by: machomaddy
5 Replies

7. Shell Programming and Scripting

Reject the record if the record in the next line does not begin with 2.

Hi, I have a input file with the following entries: 1one 2two 3three 1four 2five 3six 1seven 1eight 1nine 2ten 2eleven 2twelve 1thirteen 2fourteen The output should be: (5 Replies)
Discussion started by: supchand
5 Replies

8. Shell Programming and Scripting

Reject the record if the record in the next line does not satisfy the pattern

Hi, I have a input file with the following entries: 1one 2two 3three 1four 2five 3six 1seven 1eight 1nine 2ten The output should be 1one 2two 3three 1four 2five 3six (2 Replies)
Discussion started by: supchand
2 Replies

9. UNIX for Dummies Questions & Answers

Print first, second, every nth, and last record

does anyone have an awk one-liner to: print the first line, the second line, then every Nth line, and the last line of a file. Thanks, Kenny. (5 Replies)
Discussion started by: kenneth.mcbride
5 Replies

10. UNIX for Dummies Questions & Answers

Using sed to extract Nth record?

I have a comma-separated record and I'd like to use sed to pull the Nth record from it. It seems like it'd need to be something like this: sed -n 's/'"\,$1\,"'/&/p' Am I close? (3 Replies)
Discussion started by: doubleminus
3 Replies
Login or Register to Ask a Question