Category:AWK: Difference between revisions

m
update links
(cross ref)
m (update links)
 
(18 intermediate revisions by 6 users not shown)
Line 1:
{{language|AWK}}
|exec=interpreted
|tag=awk
}}{{CompileOnline}}
AWK is a small but powerful programming language that can process and convert text files. AWK is part of every [[Unix]]-derived system.
 
Each AWK program consists of pattern-action statements.
'''AWK''' is a general purpose programming language that is designed for processing text-based data, either in files or data streams. AWK is an example of a programming language that extensively uses the string datatype, associative arrays (that is, arrays indexed by key strings), and regular expressions. The power, terseness, and limitations of AWK programs and [[sed]] scripts inspired Larry Wall to write [[Perl]]. Because of their dense notation, all these languages are often used for writing one-liner programs.
The program reads each input line, checks lines against patterns, and runs matching actions.
For programs that never read input lines, the entire program can be one <code>BEGIN { ... }</code> block.
 
* ''List users who have /bin/ksh as a shell.''<lang awk>$ awk -F: '$7 == "/bin/ksh" { print $1 }' /etc/passwd</lang>
The reference implementation is still maintained by Brian Kernighan (the "K" in AWK).
 
AWK has only three types of variables: they are strings, floating-point numbers, and associative arrays (where every array index is a string).
==Citations==
Conversion between strings and numbers is automatic. AWK also has regular expressions, which appear in many AWK programs.
* [http://en.wikipedia.org/wiki/AWK_%28programming_language%29 Wikipedia:AWK]
There are a few built-in functions, like cos() and sprintf().
 
* ''Find average line length.''<lang awk>$ awk '{ cnt += length($0) } END { print cnt / NR }' /etc/rc</lang>
 
The name "AWK" comes from the initials of Alfred Aho, Peter Weinberger and Brian Kernighan: they invented AWK during the 1970s.
A few decades later, Kernighan continues to maintain the [[nawk|reference implementation]] of AWK.
 
==Links==
*[http://leaf.dragonflybsd.org/cgi/web-man?command=awk&section=1 awk(1) manual page], short and brief
*[https://www.gnu.org/software/gawk/ gawk] GNU awk [https://www.gnu.org/software/gawk/manual/ manual]
*[[wp:AWK (programming language)|AWK in Wikipedia]]
*[http://awk.info AWK Community Portal]
 
==Online-Execution==
* [https://ideone.com ideone.com] - gawk, mawk (both are kept up to date)
 
==Todo==
[[Tasks_not_implemented_in_AWK]]
559

edits