User's manual. Section 1.

CNT(1): count lines, words, runes, and bytes


USAGE

        usage: cnt [-Dabclmnruw] {file}
            -D: debug
            -a: count all messages and not just data msgs
            -b: count just bytes
            -c: count just characters
            -l: count just lines
            -m: count just msgs
            -n: print just totals
            -r: count just runes
            -u: use unix output
            -w: count just words
        

DESCRIPTION

Cnt counts messages, lines, words, runes, and bytes in the given files. A word is defined as a series of non-control, non-separation-punctuation, and non-space runes at the start of a file or after a non-word rune. A rune is considered as separation-punctuation if it is punctuation and non-dash and non-connector. This definition is not compatible with the venerable wc UNIX command, but it is more accurate.

If no file is given, the program prints just the count(s). Otherwise, it prints the count(s) followed by the name of each file. All counters are printed by default, unless a flag says otherwise.

EXAMPLE

        % lf -g , | cnt -u
               1       72      191     1220     1220  all/all.go
               1       33       66      420      420  all/all_test.go
               1       60      209     1311     1311  auth/auth.go
               1      163      501     2966     2966  ch/ch.go
               1      630     1806    11475    11475  cmd.go
        

The same may be achieved running

        % cnt -u ,
        

Grep for struct or var declarations in go sources, filter only those that do not contain ix, and count the words in them:

        % lf -g ,~*.go | gr -xf '^(struct|var)'  '^(}|\))\n' |
            gr -xfve ix | gr -xf '[a-zA-Z]+'  |
            cnt -mu
              15        0        1       49       49  ix.go
        

The pipe selects each word and sends a message for each one, and then counting the messages produces the expected result.

SOURCE

  • /zx/sys/src/clive/cmd/cnt


User's manual. Section 1.