Reference:
Line number starts from 0.
https://www.gnu.org/software/gawk/manual/gawk.html#Built_002din-Variables
\n
.Special patterns.
Follwing two statements have the same effect:
printf "%s %s\n", "hello", "world"
printf "%2$s %1$s\n", "world", "hello"
and prints 'hello world'.
echo 'a' | awk 'BEGIN {a="1"} /.+/ {a=a$0} END{print a}'
$ 1a
function <name> {
}
https://faculty.cs.niu.edu/~berezin/330/N/awk-fun.html
int()
https://www.gnu.org/software/gawk/manual/html_node/String-Functions.html
A trick:
length { <code> }
This works because length
of empty line gives 0
, which is considered as false value.
Thanks to tirnanog from #awk.
[[:digit:]]
: like \d
in sedvar ~ /rgx/
Example:
# -F is used to make field separator comma instead of space
# Prints lines whose first column starts with 'T'
-F "," '$1 ~ /^T/ {print $0}' awk
Another:
-f4,5 -d, pincodes.csv \
$ cut | sed "s/\"//g" \
| awk -F "," '$2 ~ /5[[:digit:]]5[[:digit:]]2[[:digit:]]/ && $1 ~ /^T/ {print $0}' \
| sort -k1 \
| less -N
print ""
: outputs a blank line (with \n
?)sprintf
, printf
awk | Meaning |
---|---|
record | line |