How to get the most occuring string from the logfile on LINUX
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.
There are several ways, but you'll have to be more specific about what data you have, what you want to find out, and what you have tried so far.
How familiar are you with pipes? You can pipe the output of sort into uniq. The -k option in the former and the -c and -f options in the latter might be of use if you are looking at whole lines. But if you want to trim some things from the line first with some fancier criteria, then you might need to look at sed or awk too.
Code:
man sort
man uniq
The manual pages are references, not tutorials. If you learn to combine them with web searches, you'll go far quickly.
Last edited by Turbocapitalist; 10-18-2017 at 09:27 AM.
The thing is, that I have a text file (which is very huge - about 400MB) and I need to find out which from the following words occurs most often and in how many lines:
OK, lets say, that sw1 occurs in the log.file 500 times.
1.Now I need to view ,the lines(outputs) 130-140 where the sw1 occurs in the log.file (something like segment).
2.And the last step is to find out how many times the strings "deny tcp" and "rt1" occur in the file log.file together.
You misunderstand what you're getting told: you do not have to keep restating your question, we understand it.
What we do NOT see, though, is any effort on your part to do this work, but rather you asking us to do it for you. Read the "Question Guidelines" link in my posting signature. We are happy to help, but you need to do your part. Post what scripts/efforts of your own that you've tried, and tell us where you're stuck. Otherwise, there are LOTS of easily-found things about searching files in Linux, counting, etc., along with loads of bash scripting tutorials. There is no shortage of resources to help you make an effort.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.