How to get the most occuring string from the logfile on LINUX
Hello,
I am a newbie in LINUX and I want to ask how can I get the most occuring string from the file in LINUX. I have a logfile on LINUX server and want to find out, which device and which log output is the most occuring. Thank you |
Welcome.
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 |
Hi.
I searched: Linux Log Files, found: https://www.cyberciti.biz/faq/linux-...ew-logs-files/ ;):hattip: then, maybe: "find matching" text in Linux: http://www.sc.edu/beaufort/library/p...es/bones.shtml ‽ :Pengy::scratch: ...have fun! :D |
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:
sw1, sw2, sw3, rt1, rt2, rt3 |
You can use grep to count the number of occurrences.
Code:
$ grep -c sw1 log.file |
Quote:
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. Thank you, |
I believe you can do all that with awk:
Code:
man awk |
Quote:
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. |
All times are GMT -5. The time now is 02:24 AM. |