Quantcast
Channel: User Dominique - Super User
Viewing all articles
Browse latest Browse all 174

Answer by Dominique for Awk command to find the most common word in a file?

$
0
0

What about this:

awk '{print $2}' file1.txt  | sort | uniq -c | sort -n | tail -n 1 | awk '{print $2}'
  • awk '{print $2}' (the first one) shows only the team
  • sort sorts :-)
  • uniq -c preceeds every word by its frequency
  • sort -n sorts by number (meaning by frequency)
  • tail -n 1 takes the last one (with the largest frequency)
  • awk '{print $2}' (the second one) only shows the team name, not the frequency

Viewing all articles
Browse latest Browse all 174

Trending Articles