K2LL33D SHELL

 Apache/2.4.7 (Ubuntu)
 Linux sman1baleendah 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64
 uid=33(www-data) gid=33(www-data) groups=33(www-data)
 safemode : OFF
 MySQL: ON | Perl: ON | cURL: OFF | WGet: ON
  >  / usr / share / doc / gawk / examples / prog /
server ip : 104.21.89.46

your ip : 172.70.100.189

H O M E


Filename/usr/share/doc/gawk/examples/prog/wc.awk
Size1.45 kb
Permissionrw-r--r--
Ownerroot : root
Create time27-Apr-2025 09:55
Last modified29-Mar-2012 04:03
Last accessed08-Jul-2025 06:08
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
# wc.awk --- count lines, words, characters
#
# Arnold Robbins, [email protected], 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 > 2)
}
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"
}
}