Skip to content

Instantly share code, notes, and snippets.

@babarot
Created May 31, 2014 01:18
Show Gist options
  • Save babarot/7c597c08afd52e353e1c to your computer and use it in GitHub Desktop.
Save babarot/7c597c08afd52e353e1c to your computer and use it in GitHub Desktop.
Count the number of command made in sh
#!/bin/sh
FILE=~/.bash_myhistory
if [ "$1" = "-h" ]; then
echo 1>&2 "usage: noc [-h|-l] [<num>]"
echo 1>&2 " -h display this help and exit"
echo 1>&2 " -l display most recently used list"
echo 1>&2 " (range: 0~<num>: default num zero)"
exit 1
fi
if [ "$1" = "-l" ]; then
for i in `seq 0 "${2:-9}"`
do
printf "%d\t%s\t%5d\n" $i $(date -v-${i}d '+%Y-%m-%d') $(grep -c `date -v-${i}d '+%Y-%m-%d'` $FILE)
done
exit 0
fi
grep -c `date -v-${1:-0}d '+%Y-%m-%d'` $FILE
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment