awk
Smth like UNIX SQL. Yup, it’s a whole language.
# Links
# Examples
Print the third column of a space-separated file:
|
|
Print the last column of each line in a file, using a comma as a field separator:
|
|
Print lines that match a condition:
|
|
Print first, second and last arguments:
|
|
# Flags
-F
- set field separator
# Variables
RS
- record separator (think “line separator”),\n
by defaultFS
- field separator, space by defaultNF
- number of fields readFNR
- current record number in FILENAMENR
- current record number in the total input stream
# Other info
Records are read one at a time, and stored in the field variable
$0
. The record is split into fields which are stored in$1
,$2
, …,$NF
.
Data input stored in fields is string, unless the entire field has numeric form and then the type is number and string.
So you can treat it like both:
|
|