I have been trying to get the unique values in each column of a tab delimited file in bash. So, I used the following command.
cut -f <column_number> <filename> | sort | uniq -c
It works fine and I can get the unique values in a column and its count like
105 Linux
55 MacOS
500 Windows
What I want to do is instead of sorting by the column value names (which in this example are OS names) I want to sort them by count and possibly have the count in the second column in this output format. So It will have to look like:
Windows 500
MacOS 105
Linux 55
How do I do this?
Mine:
This will alter the column order (awk) and then just sort the output.
Hope this will help you
Use:
The
sort -r -k1 -n
sorts in reverse order, using the first field as a numeric value. Theawk
simply reverses the order of the columns. You can test the added pipeline commands thus (with nicer formatting):