LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-18-2008, 07:20 PM   #1
lumix
Member
 
Registered: Mar 2007
Distribution: Hardy (Gnome on Ubuntu 8.04) on Compaq N600c laptop
Posts: 323

Rep: Reputation: 30
Simplest way to output nth line of file to stdout?


For the 27th, I could probably do:

Code:
head -n 27 |tail -n 1
but I feel like there's a grep or other tail option that I'm overlooking that'll do it in one command.
 
Old 05-18-2008, 08:59 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958
"sed -n 27p file.txt" appears to do the trick. You can do ranges of lines by separating the numbers with a comma. e.g. "sed -n 27,35p"

Last edited by David the H.; 05-18-2008 at 09:18 PM.
 
Old 05-18-2008, 10:41 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,040

Rep: Reputation: 1914Reputation: 1914Reputation: 1914Reputation: 1914Reputation: 1914Reputation: 1914Reputation: 1914Reputation: 1914Reputation: 1914Reputation: 1914Reputation: 1914
You can also tell it to quit - else it continues on, reading the whole file. Useful for *really* big files.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
nth line of a file in perl kadhan Programming 1 02-20-2008 12:15 PM
grep output on stdout and grep output to file don't match xnomad Linux - General 3 01-13-2007 05:56 AM
find a Nth line in text file mahabooba Programming 2 07-25-2006 12:56 AM
Command to output file content line by line aznluvsmc Programming 2 09-12-2004 08:45 PM
how to output stdout to a file SciYro Linux - Newbie 4 02-25-2004 06:08 PM


All times are GMT -5. The time now is 08:38 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration