# awk
---

-f file

awk pattern { action }


## rules
BEGIN
Routine run before file processing
END
Routine run after file processing


## special variables
NR current record number
NF number of fields in current record
FILENAME name of file being read
$n nth field of current record


## terminology
record
field
delimiter

>
<
&&
||
!

+=
++


## Regex
/<regex>/

* repeated charcter wildcard (including 0 instance)
/fe\*d/ -> fd,fed,feed,feeed,feeeed,...

+ repeated charcter wildcard (must have at least 1 instance)
/fe+d/ -> fed,feed,feeed,feeeed,...

? charcter existence wildcard represents the existence or nnexistence of some character
/fe?d/ -> fed,fd

{n} repeated character wildcard of n instances
/fe{3}d/ -> feeed

/fe{3,5}d/ -> feeed,feeeeed
/fe{3,}d/ -> feeed,feeeed,feeeeed,...


. single character wildcard
^ start of line
$ end of line
~ regex comparison
!~ negative regex comparison
[] bracket expression
[^] complemented bracket expression
() regex grouper
| alternation operator; one of the regex expressions connected by this operator must be satisfied to return true 


## statement
print
```
print argument
```

if
```
if (condition) then-body [else else-body]
```

for
```
for (it;end-condtion;update-it) body
```

do while
```
do body while (condition)
```

exit
```
exit [return-code]
```

switch
```
switch (expression) {
	case value-or-regex:
		case-body
		break;
	default:
		default-body
		break;
}
```


## Functions
atan2
sin
cos
tan
sqrt
exp
log
rand

gsub
