shell script :: how to print string that appeared maximum number of times in file ??
alpha gamma alpha beta
Desired output -->
Thanks in advance.
PS: Best would be if one can suggest an in-line shell (bash) script command (i.e. something of type "cat file.txt | <some_command>").
There are probably many ways to do it, but here is one:
- cat file.txt
- convert all whitespace to newlines
- sort it
- check unique lines, and add the word count first
- sort by word count (numerical) reverse
- only use the first line
- print second word (skip the count)
despite guessing that this should be a homework type qns, here's a partial solution. do the finding of max number yourself.
This does smell like homework. Then why do you respond with solutions when the OP doesn't even show what he/she has attempted?
If there were some problems with what the OP presents then addressing that would be appropriate.
The LQ Rules don't state that we cannot help but;
|All times are GMT -5. The time now is 11:08 PM.|