BradleyA / user-files

General user files for new systems
MIT License
2 stars 0 forks source link

hooks/(pre,post)-commit add code for tracking and reporting the return code > 1 #28

Closed BradleyA closed 5 years ago

BradleyA commented 5 years ago

hooks/(pre,post)-commit add code for tracking and reporting return code > 1

cmd >> file.txt 2>&1
>>> SAST: post-commit
Number of test cases = 4
Number of test cases pass = 1
Number of test cases fail = 1
Number of test cases error = 2
   2 1
   124 2
BradleyA commented 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