-2

I have a document named names.txt . I want to write a command that finds the most repeated name and shows me how many times this name has been repeated.In case of a the, it will show a random name of the tied names.

For example:

The names.txt file includes the names: jason, bob, nick, jason and alice

I want it to show:

2 jason

Please help me guys!

18
  • 3
    What have you already tried? At which point did you get stuck?
    – Hennes
    Nov 9, 2017 at 17:50
  • I have tried different methods but i really dont know how to do it. Do you know some ways? Nov 9, 2017 at 17:53
  • ... and what is the format of the file (comma separated? one name per line?), and what do you want to happen in the case of a tie? Nov 9, 2017 at 17:54
  • The format is Comma Separated. In case of a tie it will show randomly one of the tied. Nov 9, 2017 at 17:56
  • What are those different methods you tried?
    – derHugo
    Nov 9, 2017 at 17:57

1 Answer 1

1

This should answer the poster's problem: tr , '\n' <names.txt | sort | uniq -c | sort -n | tail -1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.