how to specify last line of file ? 
Author Message
 how to specify last line of file ?

The following sed statement will print the last
line of a file. What is the awk/nawk equivalent ?

        sed -n '$p' filename



Mon, 14 Dec 1998 03:00:00 GMT  
 how to specify last line of file ?

Quote:

>The following sed statement will print the last
>line of a file. What is the awk/nawk equivalent ?

>    sed -n '$p' filename

awk '{ line = $0 }; END { print line }' filename
--
Arnold Robbins -- guest account at Emory Math/CS        | Laundry increases

"some things are worth preserving." -- Brian Kernighan        | number of children.
upon running `gawk --nostalgia'.                        | -- Miriam A. Robbins


Mon, 14 Dec 1998 03:00:00 GMT  
 how to specify last line of file ?

Quote:


> : The following sed statement will print the last
> : line of a file. What is the awk/nawk equivalent ?

> :       sed -n '$p' filename

> Try this script:

> { last = $0 }
> END { print last }

> Juergen Mueller


If you're on a Unix system, you might try tail -1 filename.  I think the
syntax is right; if not, check the man page.  The default behavior for
tail is the last 10 lines, I believe.

Hope this helps.

= Steve =
--
Steve W. Jackson
Montgomery, AL

Do you believe in Macintosh? Learn how to help the Macintosh
cause by subscribing to EvangeList, a listserver for Macintosh
fans. To receive instructions, send an email to



Mon, 14 Dec 1998 03:00:00 GMT  
 how to specify last line of file ?

: The following sed statement will print the last
: line of a file. What is the awk/nawk equivalent ?

:       sed -n '$p' filename

Try this script:

{ last = $0 }
END { print last }

Juergen Mueller



Tue, 15 Dec 1998 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. specifying the file and line

2. read the last line in file

3. join last 2 lines of a file

4. deleting newline from last line in file

5. print last line of input file

6. How to read the x last lines of a text file

7. How to read the last line of http:// file

8. File: How to read the last line?

9. Best way to get Last line of file?

10. last 20 lines of a file on WinDoze ?

11. Deleting the last lines in a text file with tcl

12. Removing last line while appending to file

 

 
Powered by phpBB® Forum Software