Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Actually, this was an old task given from one of the former teachers who used to work here. He was mostly known as 'Prf. Magic' because of his perception of achieving the unachievable. This could include unconventional methods of doing the simplest tasks using the most tedious and outdated methods: Such as this one.
He is now retired and lives somewhere in Spain with his hot and young wife, Nastasia. Most likely sipping piña coladas from her belly button on a daily basis
Thank you for the interest
Interesting. Even with Nastasia, he appears to have proved that achieving the unachievable is possible.
Do you have the exact wording of the task that he set?
still not sure what do you need. (for example you need the latest log files or the last lines of logfiles or what?).
By the way logrotate will drop out the old messages, so you will see only the latest in /var/log. Regardless of the command you use (awk/grep/perl/cat/whatever)
That is a very interesting suggestion. Would this still include cat somewhere on the line? - That is, without taking away its function of course. If so, would you please consider to put it in a formatted shell-command? Waiting to run an output?
Quote:
Originally Posted by pan64
still not sure what do you need. (for example you need the latest log files or the last lines of logfiles or what?).
My sincerest apologies. I only wish to reduce the output like so:
Quote:
Originally Posted by Pomerano
Now, basically - in plain English - what I ultimately would like to do is...:
To reduce the number of the results who are triggered by the line command cat /var/log/messages. The only condition I have is that it cannot replace the command cat in any way.
My God, I still don't understand. cat is just a simple reader, it will just read something (file, stdin) and push it toward to the next stage (pipe, file, whatever). The "thing" you need is - I think - something else.
I still can't figure out what the object is. Do you want to show the most recent log entries in /var/log/messages? Then
Code:
$ cat /var/log/messages
will do that. It will scroll through the whole file, but whats displayed at the end will be the latest messages.
Thank you for the reply. Could this line of code have something added (without removing "cat") to ONLY show the very last results in that very output?
Because that is all I want.
Thank you for the reply. Could this line of code have something added (without removing "cat") to ONLY show the very last results in that very output?
Because that is all I want.
Thanks again!
OH!
Code:
cat /var/log/messages | tail -2
(-2, because you said results) The number can be anything, and if left off, defaults to 10.
Note that you can just
(-2, because you said results) The number can be anything, and if left off, defaults to 10.
Note that you can just
Code:
tail -2 /var/log/messages
to yield the same result.
This was a fantastic reply, however the real deal breaker was this part, simple as that! Thank you so much!
Quote:
Originally Posted by scasey
OH!
Code:
cat /var/log/messages | tail -2
From a historic point-of-view... this task was not solved by using a UUOC, like $ tail, or such. However, this was all I wanted to know. I will summarize my research for anyone else looking for anything similar at the very bottom...Case closed, thank you! (+1)
By definition, cat dumps the entire contents of a file, so to limit output requires a second tool.
A UUOC, but
Code:
cat /var/log/messages | less +G
"UUOC", thank you! Also, the code less did some of it, I just couldn't quite contain it to the extent of keeping it "less" (non-intentional pun) enough to serve its purpose. Although I replaced less +G with just less or less -1. Still very helpful, though, and I am certain that I am the blind one here. Therefore missing the solution. (+ 1)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.