LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   how to get the last line of an output (https://www.linuxquestions.org/questions/linux-general-1/how-to-get-the-last-line-of-an-output-857796/)

mahmoodn 01-21-2011 09:28 AM

how to get the last line of an output
 
I want to write a bash script to run a command and get the last line of the output of that command.
For example, the output of "cat /proc/zoneinfo" is:
Code:

Node 0, zone      DMA
  pages free    3948
        min      2
        low      2
        high    3
        scanned  0
        spanned  4080
        present  3807
    nr_free_pages 3948
.....
.....
  vm stats threshold: 70
  all_unreclaimable: 0
  prev_priority:    12
  start_pfn:        6422528
  inactive_ratio:    8

How can I get the last line in a separated format?

Nylex 01-21-2011 09:31 AM

To get the last line, you can use

tail -n 1 /proc/zoneinfo

See the man page for tail for more details. What do you mean by "separated format"?

pwc101 01-21-2011 09:32 AM

Code:

tail -1 /proc/zoneinfo

mahmoodn 01-21-2011 11:11 AM

Thanks. it was useful

trickykid 01-26-2011 01:10 PM

On a side note, proc files can change. If you know what you really need from it, grep for the pattern you wish to grab.

grep inactive_ratio /proc/zoneinfo


All times are GMT -5. The time now is 01:23 AM.