summaryrefslogtreecommitdiff
path: root/sort-uniq-count-rank
blob: 285197a0c143d38228812df395fa0cbadd92b4c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/sh

# Public domain notice for all NCBI EDirect scripts is located at:
# https://www.ncbi.nlm.nih.gov/books/NBK179288/#chapter6.Public_Domain_Notice   

flags="f"
if [ -n "$*" ]
then
  flags=$( echo " $*" | sed 's/[^bfinrs]//g' )
  if [ -z "$flags" ]
  then
    flags="s"
  fi
fi
grep '.' |
sort "-$flags" |
uniq -i -c |
awk '{ n=$1; sub(/[ \t]*[0-9]+[ \t]/, ""); print n "\t" $0 }' |
sort -t "$(printf '\t')" -k 1,1nr -k "2$flags"