LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 10-18-2017, 09:19 AM   #1
DusanM
LQ Newbie
 
Registered: Oct 2017
Posts: 3

Rep: Reputation: Disabled
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
 
Old 10-18-2017, 09:24 AM   #2
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,371
Blog Entries: 3

Rep: Reputation: 2183Reputation: 2183Reputation: 2183Reputation: 2183Reputation: 2183Reputation: 2183Reputation: 2183Reputation: 2183Reputation: 2183Reputation: 2183Reputation: 2183
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
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.
 
2 members found this post helpful.
Old 10-18-2017, 10:04 AM   #3
jamison20000e
Senior Member
 
Registered: Nov 2005
Location: ...uncanny valley... infinity\1975; (randomly born:) Milwaukee, WI, US( + travel,) Earth( I wish,) END BORDER$!◣◢┌∩┐ Fe26-E,e...
Distribution: any GPL that works well on my cheapest; has been KDE or CLI but open... http://goo.gl/NqgqJx &c ;-)
Posts: 3,874
Blog Entries: 2

Rep: Reputation: 1314Reputation: 1314Reputation: 1314Reputation: 1314Reputation: 1314Reputation: 1314Reputation: 1314Reputation: 1314Reputation: 1314Reputation: 1314
Hi.

I searched: Linux Log Files, found: https://www.cyberciti.biz/faq/linux-...ew-logs-files/

then, maybe: "find matching" text in Linux: http://www.sc.edu/beaufort/library/p...es/bones.shtml

...have fun!
 
Old 10-18-2017, 03:54 PM   #4
DusanM
LQ Newbie
 
Registered: Oct 2017
Posts: 3

Original Poster
Rep: Reputation: Disabled
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
 
Old 10-18-2017, 04:36 PM   #5
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,511

Rep: Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006Reputation: 1006
You can use grep to count the number of occurrences.
Code:
$ grep -c sw1 log.file
If you want to you make a script to do every string without further interaction.
 
1 members found this post helpful.
Old 10-19-2017, 04:02 PM   #6
DusanM
LQ Newbie
 
Registered: Oct 2017
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by AwesomeMachine View Post
You can use grep to count the number of occurrences.
Code:
$ grep -c sw1 log.file
If you want to you make a script to do every string without further interaction.
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.


Thank you,

Last edited by DusanM; 10-19-2017 at 04:05 PM.
 
Old 10-19-2017, 05:04 PM   #7
lsalab
LQ Newbie
 
Registered: Jan 2009
Posts: 24

Rep: Reputation: 3
I believe you can do all that with awk:

Code:
man awk
 
Old 10-19-2017, 05:11 PM   #8
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 22,222

Rep: Reputation: 5968Reputation: 5968Reputation: 5968Reputation: 5968Reputation: 5968Reputation: 5968Reputation: 5968Reputation: 5968Reputation: 5968Reputation: 5968Reputation: 5968
Quote:
Originally Posted by DusanM View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why this memory leak occuring kbarani Linux - Software 2 08-25-2009 11:53 PM
Shell scripting: Print output to logfile, error to logfile & screen stefanlasiewski Programming 18 05-22-2008 01:47 PM
Error occuring while installing the red hat linux jitu_linux Linux - Hardware 2 03-29-2008 03:17 PM
Odd hardware problem occuring in linux and windows. RoaCh Of DisCor Linux - Hardware 7 04-18-2005 06:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration