Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 02-08-2003, 06:44 PM   #1
Registered: Jan 2003
Location: S.E. England
Distribution: Redhat 8.0
Posts: 64

Rep: Reputation: 15
Printing a specific line

Hey, i have search but i must be looking for the wrong thing cos i cant find any answers.
Basically, in the terminal, how can i print a specified line from a file (like line 4). i have read through grep, more, less and cat manuals but none of them seem to have the option to print only one specified line.

does anyone know of a command that will do this?

Many thanks

Old 02-10-2003, 10:11 AM   #2
Registered: Oct 2002
Location: Curitiba - Brazil
Distribution: Conectiva
Posts: 334

Rep: Reputation: 30
Sed does:

# sed -n 1p file

this will print the first line of a file...
Old 02-10-2003, 10:59 AM   #3
Senior Member
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
Well... I imagine there is a better way than this, but you could use a combination of head and tail. Say you wanted line 15 from a file named my_text.txt:
head -15 my_text.txt | tail -1


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
Kill specific Wine program from Command Line Brian114 Linux - Software 4 06-07-2011 04:02 AM
Extracting a specific line from an ASCII file heyyou Programming 7 03-21-2005 04:19 PM
Command line tools to Find files with specific text naps Linux - Software 5 11-15-2004 04:46 AM
Shell script - how to show a specific line of a text file davi_cabral Linux - Software 3 09-28-2004 01:39 PM
starting X from the command line in a specific resolution jdaniel Linux - General 5 09-10-2003 09:25 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:34 PM.

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