LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 10-14-2007, 09:59 AM   #1
new_2_unix
LQ Newbie
 
Registered: Oct 2007
Posts: 26

Rep: Reputation: 15
how to print a specific line number with cat


hi,

with 'cat -n filename' i can see the contents of filename with the line numbers prefixed to it as follows:

1 Line One
2 Line Two

Is there way to tell cat to print just the line with number '2'? i saw the man pages and looked at some examples also but it doesn't seem to define it.

any ideas? thanks!!
 
Old 10-14-2007, 10:22 AM   #2
The_JinJ
Member
 
Registered: Apr 2004
Location: Scotland
Distribution: Suse, OpenWRT
Posts: 299

Rep: Reputation: 30
This would work

Code:
cat /yourfile | sed '3!d'
Replace the 3 with thte line number you need

EDIT

Or (more sensible)

sed '3!d' /yourfile

Last edited by The_JinJ; 10-14-2007 at 10:28 AM.
 
Old 10-14-2007, 10:47 AM   #3
new_2_unix
LQ Newbie
 
Registered: Oct 2007
Posts: 26

Original Poster
Rep: Reputation: 15
that does it! thanks!
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
cat: output specific number of lines mikeshn Linux - Software 8 01-24-2017 11:08 AM
Print from a line number hammertime1983 Linux - Newbie 3 08-20-2007 07:06 AM
sed / awk command to print line number as column? johnpaulodonnell Linux - Newbie 2 01-22-2007 07:07 AM
Print line number X of a file (in shell) rheza Programming 4 01-04-2005 05:55 PM
Quick Q: Command to print line number X? KneeLess Linux - Software 1 05-27-2004 07:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:30 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