/usr/share/doc/gawk/examples/prog
NameSizeModeActions
alarm.awk23690644editdlrm
anagram.awk13580644editdlrm
awksed.awk5150644editdlrm
cut.awk36980644editdlrm
dupword.awk5070644editdlrm
egrep.awk19540644editdlrm
extract.awk18830644editdlrm
guide.awk1650644editdlrm
histsort.awk2830644editdlrm
id.awk12490644editdlrm
igawk.sh31890644editdlrm
indirectcall.awk19570644editdlrm
labels.awk10140644editdlrm
pi.awk3410644editdlrm
split.awk11980644editdlrm
tee.awk7700644editdlrm
testbits.awk7360644editdlrm
translate.awk11820644editdlrm
uniq.awk27000644editdlrm
wc.awk14800644editdlrm
wordfreq.awk3470644editdlrm
Edit: /usr/share/doc/gawk/examples/prog/wc.awk (1480B)
# wc.awk --- count lines, words, characters # # Arnold Robbins, arnold@skeeve.com, Public Domain # May 1993 # Options: # -l only count lines # -w only count words # -c only count characters # # Default is to count lines, words, characters # # Requires getopt() and file transition library functions BEGIN { # let getopt() print a message about # invalid options. we ignore them while ((c = getopt(ARGC, ARGV, "lwc")) != -1) { if (c == "l") do_lines = 1 else if (c == "w") do_words = 1 else if (c == "c") do_chars = 1 } for (i = 1; i < Optind; i++) ARGV[i] = "" # if no options, do all if (! do_lines && ! do_words && ! do_chars) do_lines = do_words = do_chars = 1 print_total = (ARGC - i > 1) } function beginfile(file) { lines = words = chars = 0 fname = FILENAME } function endfile(file) { tlines += lines twords += words tchars += chars if (do_lines) printf "\t%d", lines if (do_words) printf "\t%d", words if (do_chars) printf "\t%d", chars printf "\t%s\n", fname } # do per line { chars += length($0) + 1 # get newline lines++ words += NF } END { if (print_total) { if (do_lines) printf "\t%d", tlines if (do_words) printf "\t%d", twords if (do_chars) printf "\t%d", tchars print "\ttotal" } }