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 10-28-2008, 11:54 PM   #1
pheardotcom
LQ Newbie
 
Registered: Oct 2008
Posts: 4

Rep: Reputation: 0
A Command to display a specific line??


Hello,
i'm new to linux, and i'm also taking a course on it, so i need some help

the question is: The file 'threelines' contains 3 lines of text. Display the middle line on the screen. You are not allowed to use the 'more' command.

try using a combination of head and tail

thank you.

Last edited by pheardotcom; 10-29-2008 at 12:07 AM.
 
Old 10-29-2008, 12:22 AM   #2
klearview
Member
 
Registered: Aug 2006
Location: London
Distribution: Debian, Kubuntu
Posts: 572

Rep: Reputation: 75
Hi,

A few ways to do this. Here is one:

tail -2 <file> | line

Another way: number the lines with 'nl <file>' and use grep (nl <file> | grep -w 2).
 
Old 10-29-2008, 12:24 AM   #3
klearview
Member
 
Registered: Aug 2006
Location: London
Distribution: Debian, Kubuntu
Posts: 572

Rep: Reputation: 75
With head and tail only:

tail -2 <file> | head -1
 
Old 10-29-2008, 12:30 AM   #4
pheardotcom
LQ Newbie
 
Registered: Oct 2008
Posts: 4

Original Poster
Rep: Reputation: 0
that worked perfectly thank you
 
Old 11-04-2008, 03:08 PM   #5
nishamathew1980
Member
 
Registered: Oct 2008
Posts: 37

Rep: Reputation: 16
I loved the tail and head solution. @klearview - RESPECT!


Linux Archive

Last edited by nishamathew1980; 11-09-2008 at 05:57 AM.
 
Old 11-02-2009, 08:56 PM   #6
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by deandre_7 View Post
This is the question.

Search the file 'data' for all of the lines that contain the pattern 'uli101'and put those lines in the file 'matches'.

Any help would be appreciated. Thanks
You have already posted this question in another thread. And you have gotten a reply.
 
Old 11-02-2009, 10:29 PM   #7
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
Originally Posted by lutusp View Post
You have already posted this question in another thread. And you have gotten a reply.
Actually, this one came first---so deleted this one and will now re-open the other thread.
 
Old 11-03-2009, 12:15 AM   #8
pheardotcom
LQ Newbie
 
Registered: Oct 2008
Posts: 4

Original Poster
Rep: Reputation: 0
gotten?

Got is already in past-tense there is no need for you to add the 'ten' at the end.
 
  


Reply

Tags
commands


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 05:02 AM
Command line: How do I backup files modified after a specific date only rm_-rf_windows Linux - General 2 06-28-2007 09:34 PM
Command line tools to Find files with specific text naps Linux - Software 5 11-15-2004 05:46 AM
Command to display whole filestructure hierarchy f/ command line? mjewell Linux - Newbie 10 01-19-2004 11:48 AM
starting X from the command line in a specific resolution jdaniel Linux - General 5 09-10-2003 10:25 PM


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