Size: 1108
Comment:
|
Size: 1055
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 5: | Line 5: |
There are several implementation of '''`awk(1)`''': | There are several implementations: |
Line 26: | Line 26: |
A better example is extracting the hostnames from the [[Linux/hosts|hosts file]]. | A more realistic example is extracting hostnames from the [[Linux/hosts|hosts file]]. |
Line 32: | Line 32: |
The awk syntax can be written to a script file and executed like: | Execute a script as: |
Line 42: | Line 42: |
To make an awk script executable, use `#! /bin/awk -f` as the shebang line. | To make an `awk(1)` script executable, use `#! /bin/awk -f` as the shebang line. |
Awk
awk(1) is a scripting language designed for text processing.
There are several implementations:
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 more realistic example is extracting hostnames from the hosts file.
awk '/^[^#]/ { print $2 }' /etc/hosts
Execute a script as:
awk -f my-hosts-parser.awk /etc/hosts
Shebang
To make an awk(1) script executable, use #! /bin/awk -f as the shebang line.