Debian Codegraph @

letter-count.sh

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 # letter-count.sh: Counting letter occurrences in a text file.
3 # Written by Stefano Palmeri.
4 # Used in ABS Guide with permission.
5 # Slightly modified by document author.
6
7 MINARGS=2 # Script requires at least two arguments.
8 E_BADARGS=65
9 FILE=$1
10
11 let LETTERS=$#-1 # How many letters specified (as command-line args).
12 # (Subtract 1 from number of command-line args.)
13
14
15 show_helpscip-shell shell abs-guide 10-4 show_help().(){
16 echoscip-shell system . . echo.
17 echoscip-shell system . . echo. Usage: `basenamescip-shell system . . basename. $0` file letters
18 echoscip-shell system . . echo. Note: `basenamescip-shell system . . basename. $0` arguments are case sensitive.
19 echoscip-shell system . . echo. Example: `basenamescip-shell system . . basename. $0` foobar.txt G n U L i N U x.
20 echoscip-shell system . . echo.
21 }
22
23 # Checks number of arguments.
24 if [scip-shell system . . `[`. $# -lt $MINARGS ]; then
25 echoscip-shell system . . echo.
26 echoscip-shell system . . echo. "Not enough arguments."
27 echoscip-shell system . . echo.
28 show_helpscip-shell shell abs-guide 10-4 show_help().
29 exit $E_BADARGS
30 fi
31
32
33 # Checks if file exists.
34 if [scip-shell system . . `[`. ! -f $FILE ]; then
35 echoscip-shell system . . echo. "File \"$FILE\" does not exist."
36 exit $E_BADARGS
37 fi
38
39
40
41 # Counts letter occurrences .
42 for n in `seqscip-shell system . . seq. $LETTERS`; do
43 shift
44 if [[ `echo -n "$1" | wc -c` -eq 1 ]]; then # Checks arg.
45 echoscip-shell system . . echo. "$1" -\> `catscip-shell system . . cat. $FILE | trscip-shell system . . tr. -cd "$1" | wcscip-shell system . . wc. -c` # Counting.
46 else
47 echoscip-shell system . . echo. "$1 is not a single char."
48 fi
49 done
50
51 exit $?
52
53 # This script has exactly the same functionality as letter-count2.sh,
54 #+ but executes faster.
55 # Why?