Server IP : 85.214.239.14 / Your IP : 18.189.182.15 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/2/task/2/cwd/proc/2/cwd/usr/share/doc/gawk/examples/prog/ |
Upload File : |
# wc.awk --- count lines, words, characters, bytes # # Arnold Robbins, arnold@skeeve.com, Public Domain # May 1993 # Revised September 2020 # Options: # -l only count lines # -w only count words # -c only count bytes # -m only count characters # # Default is to count lines, words, bytes # # Requires getopt() and file transition library functions # Requires mbs extension from gawkextlib @load "mbs" BEGIN { # let getopt() print a message about # invalid options. we ignore them while ((c = getopt(ARGC, ARGV, "lwcm")) != -1) { if (c == "l") do_lines = 1 else if (c == "w") do_words = 1 else if (c == "c") do_bytes = 1 else if (c == "m") do_chars = 1 } for (i = 1; i < Optind; i++) ARGV[i] = "" # if no options, do lines, words, bytes if (! do_lines && ! do_words && ! do_chars && ! do_bytes) do_lines = do_words = do_bytes = 1 print_total = (ARGC - i > 1) } function beginfile(file) { lines = words = chars = bytes = 0 fname = FILENAME } function endfile(file) { tlines += lines twords += words tchars += chars tbytes += bytes if (do_lines) printf "\t%d", lines if (do_words) printf "\t%d", words if (do_chars) printf "\t%d", chars if (do_bytes) printf "\t%d", bytes printf "\t%s\n", fname } # do per line { chars += length($0) + 1 # get newline bytes += mbs_length($0) + 1 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 if (do_bytes) printf "\t%d", tbytes print "\ttotal" } }