LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-21-2011, 09:28 AM   #1
mahmoodn
Member
 
Registered: May 2010
Posts: 427

Rep: Reputation: 16
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?
 
Old 01-21-2011, 09:31 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
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"?
 
Old 01-21-2011, 09:32 AM   #3
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Code:
tail -1 /proc/zoneinfo
 
1 members found this post helpful.
Old 01-21-2011, 11:11 AM   #4
mahmoodn
Member
 
Registered: May 2010
Posts: 427

Original Poster
Rep: Reputation: 16
Thanks. it was useful
 
Old 01-26-2011, 01:10 PM   #5
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading screen output line by line basildon Linux - Newbie 1 09-23-2008 01:33 PM
help with c program to read each line from text file, split line , process and output gkoumantaris Programming 12 07-01-2008 12:38 PM
output on the same line ygloo Programming 10 11-10-2006 03:33 PM
Grep's line numbers parsed into one line of output. judgex Programming 8 08-14-2006 04:22 AM
Command to output file content line by line aznluvsmc Programming 2 09-12-2004 07:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration