LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   A Command to display a specific line?? (https://www.linuxquestions.org/questions/linux-newbie-8/a-command-to-display-a-specific-line-679685/)

pheardotcom 10-28-2008 10:54 PM

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.

klearview 10-28-2008 11:22 PM

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).

klearview 10-28-2008 11:24 PM

With head and tail only:

tail -2 <file> | head -1

pheardotcom 10-28-2008 11:30 PM

that worked perfectly thank you :D

nishamathew1980 11-04-2008 02:08 PM

I loved the tail and head solution. @klearview - RESPECT!
:)

Linux Archive

lutusp 11-02-2009 07:56 PM

Quote:

Originally Posted by deandre_7 (Post 3741992)
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.

pixellany 11-02-2009 09:29 PM

Quote:

Originally Posted by lutusp (Post 3742006)
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.

pheardotcom 11-02-2009 11:15 PM

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


All times are GMT -5. The time now is 07:36 PM.