Differences between revisions 2 and 5 (spanning 3 versions)
Revision 2 as of 2022-05-21 15:48:50
Size: 1349
Comment:
Revision 5 as of 2022-09-27 01:32:36
Size: 1108
Comment:
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
The '''Awk programming language''' is a scripting language for operating on text files. It is self-described as being a "data driven" tool; "you describe the data you want to work with and then what to do when you find it". '''`awk(1)`''' is a scripting language designed for text processing.
Line 5: Line 5:
There are several implementation of `awk(1)`, the most widely-used being GNU awk (or gawk). Brian Kernighan [[https://github.com/onetrueawk/awk|open-sourced]] the original Unix awk. [[BusyBox]] includes an implementation of POSIX awk. There are several revival/modernization projects, notably [[https://github.com/benhoyt/goawk|GoAWK]] which supports CSV as an input and output format. There are several implementation of '''`awk(1)`''':
Line 7: Line 7:
See the [[https://www.gnu.org/software/gawk/manual/gawk.html|User Manual]] for more upstream information.  * Brian Kernighan [[https://github.com/onetrueawk/awk|open-sourced]] the original Unix implementation
 * '''GNU awk''' (or '''gawk''') is an extended implementation
 * [[BusyBox]] implements POSIX `awk(1)`
 * the modern revivalist [[https://github.com/benhoyt/goawk|GoAWK]]

See the [[https://www.gnu.org/software/gawk/manual/gawk.html|GNU awk User Manual]] for further documentation.
Line 17: Line 22:
A hello world program isn't helpful for awk, but here's an example anyway.
Line 23: Line 26:
A better example would involve parsing a [[Linux/hosts|hosts file]]. A better example is extracting the hostnames from the [[Linux/hosts|hosts file]].
Line 48: Line 51:
 * [[Awk/Actions|Actions]]

Awk

awk(1) is a scripting language designed for text processing.

There are several implementation of awk(1):

  • Brian Kernighan open-sourced the original Unix implementation

  • GNU awk (or gawk) is an extended implementation

  • BusyBox implements POSIX awk(1)

  • the modern revivalist GoAWK

See the GNU awk User Manual for further documentation.


Example

awk 'BEGIN { print "hello world" }'

A better example is extracting the hostnames from the hosts file.

awk '/^[^#]/ { print $2 }' /etc/hosts

The awk syntax can be written to a script file and executed like:

awk -f my-hosts-parser.awk /etc/hosts

Shebang

To make an awk script executable, use #! /bin/awk -f as the shebang line.


Syntax


CategoryRicottone

Awk (last edited 2023-06-22 20:03:20 by DominicRicottone)