awk |
awk script outline
- #!/usr/bin/awk -f
- BEGIN {action}
- pattern {action}
if no pattern, do action for every line
if no action, print matching lines- END {action}
Misc
- fields for each record (line) are broken into variables $1, $2...
Variables
- NF (number of fields) in current record, $NF is value of last field
- NR (number of record) is current record#
- FS (field separator) usually blank, can also set with -F on command line
- RS (record separator) usually a newline; do RS="" when records are multiple lines with each record separated by a blank line
- OFS (output field separator) is usually blank
- ORS (output record separator) is usually newline
examples
- echo "Hello, world." > hello.txt
awk '{print}' < hello.txt- awk 'BEGIN {print Hello}'
Links
|