LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-09-2006, 06:18 AM   #1
basak
Member
 
Registered: Jul 2006
Posts: 41

Rep: Reputation: 15
a simple question


Hi..Is there a bash shell command which exactly selects and returns the given numbered line in a file (ex. 3rd line)?Thanks..
 
Old 08-09-2006, 06:30 AM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Do you mean something like this?
Code:
sed -n '3p' file.txt
 
Old 08-09-2006, 10:02 PM   #3
Valdis Grinbergs
Member
 
Registered: Dec 2005
Distribution: Debian
Posts: 30

Rep: Reputation: 25
basak and homey,

Here is another way:
head -3 file.txt | tail -1
This captures the first 3 lines of file.txt
then displays only the last of these lines.

This approach can easily be modified to get a range of lines,
for example:
head -2 file.txt | tail -3
gives the third line and the lines directly before and after it (lines 2-4).

'head' and 'tail' are two simple utilities that are very useful when you do not need to do something more complicated with sed, awk, perl, etc. You might want to check out the man pages for both.

If you find another (and especially if you find a better) way, please post it here.
 
Old 08-10-2006, 12:52 AM   #4
Oxagast
Member
 
Registered: Aug 2003
Location: Mocksville, NC, USA
Distribution: Gentoo, Slackware.
Posts: 410

Rep: Reputation: 30
Sed makes my brain bleed. I wrote a log stripper which implimented sed heavily... gahhhhh. Worked amazing when I finally figured out how to do all that I wanted to do though... very versatile program.
 
  


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
Two things: (Probably Simple) Grub question, and a gDesklets question Wilffo Linux - Software 3 05-20-2006 01:33 PM
Ubuntu Fluxbox simple question, simple answer? generallimptoes Linux - Software 3 09-26-2005 02:03 PM
simple question Kilahchris Linux - Newbie 3 10-29-2004 11:41 AM
Installing Programs - A simple question from my simple mind jmp875 Linux - Newbie 6 02-18-2004 09:03 PM
simple question seeking simple answer enzo250gto Linux - Newbie 1 10-27-2001 04:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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

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