Closed BradleyA closed 5 years ago
Great answer, here's what I use to get a wordcount out of file with sentences: tr ' ' '\n' < $FILE | sort | uniq -c | sort -nr > wordcount.txt. The first command replaces spaces with newlines, allowing for the rest of the command to work as expected.
In the particular case were the lines you are sorting are numbers, you need use sort -gr instead of sort -nr
Actually, when the data are numbers, -gr works better. Try these two examples, differing only in the g and n flags: echo "1 11 1 2" | tr ' ' '\n' | sort | uniq -c | sort -nr and echo "1 11 1 2" | tr ' ' '\n' | sort | uniq -c | sort -gr. The first one sorts incorrectly, but not the second one.
echo "45 256 0 1 2 124 0 2 0 0" | tr ' ' '\n' | sort | uniq -c | sort -k 2 -n
hooks/(pre,post)-commit add code for tracking and reporting return code > 1