LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Quick Question of Newbie... (https://www.linuxquestions.org/questions/linux-newbie-8/quick-question-of-newbie-784876/)

djsez123 01-26-2010 11:36 AM

Quick Question of Newbie...
 
Hey Guys! Thanks for helping out. Here is what I need help with.

Assume that i've already navigated to the directory containing this file.

What command(s) would you use to find the last time the phrase “Hosting” appears in a file? I need 2 different ways to accomplish this.

Thanks!!

Steve

EricTRA 01-26-2010 11:41 AM

Hello and welcome to LinuxQuestions Steve,

Your question looks like homework to me and per the LQ rules there will not be a lot of users inclined to offer you a 'ready to go' answer. On the other hand if you've figured out something but are getting errors using a command or script, we'd be happy to point you in the right direction.

That being said: Enjoy Linux!

Kind regards,

Eric

djsez123 01-26-2010 11:50 AM

Well, not really homework, but a question I was asked. I have one solution, which I have pasted below, but I can't figure out how to go about doing it a diffrent way.

grep -wn "Hosting" messages - This command will display all lines that have Hosting, and also include the line number

None the less, thanks!!

Steven

phlyer 01-26-2010 12:01 PM

assuming you are referring to the last occurrence of <pattern> on a line in <file>,
you could pipe your grep output into tail
Try:
Code:

grep <pattern> <file> | tail -n1
for more details, please see "man tail"

Hope that helps
M


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