Jump to content

Category:AWK: Difference between revisions

{{CompileOnline}} - but link needs to be in lowercase
m (awk and shell are not the only scripting languages to support numbers and strings)
({{CompileOnline}} - but link needs to be in lowercase)
Line 2:
|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. 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.
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>
 
AWK has only three types of variables: they are strings, floating-point numbers, and associative arrays (where every array index is a string). Conversion between strings and numbers is automatic. AWK also has regular expressions, which appear in many AWK programs. There are a few built-in functions, like cos() and sprintf().
Conversion between strings and numbers is automatic. AWK also has regular expressions, which appear in many AWK programs.
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.
A few decades later, Kernighan continues to maintain the [[nawk|reference implementation]] of AWK.
 
==Links==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.