Desktop
System
- Ansible from scratch
- Ansible
- AWX
- Using Docker
- MySQL Replication
- Nginx
- Percona XtraDB Cluster
- SELinux Samba share
- Sphinx
- Systemd
Bash
Awk
- Getting Started with awk
- Running awk and gawk
- Regular Expressions
- Reading Input Files
- Record number
- Record splitting with standard awk
- Record splitting with gawk
- Fields
- Contents of a field
- How fields are separated
- Each character a separate field
- FS from the command line
- Field-splitting summary
- Record-splitting summary
- Multiple-line records
- Explicit input with getline
- Getline summary
- Input with a timeout
- Printing Output
- Expressions
- Patterns, Actions, and Variables
- Arrays in awk
- Functions
Regular Expressions¶
Use regular expressions¶
/regexp/
awk '/li/ { print $2 }' mail-list
exp ~ /regexp/
awk '$1 ~ /^J/' inventory-shipped
exp !~ /regexp/
awk '$1 !~ /^J/' inventory-shipped
echo aaaabcd | awk '{ sub(/a+/, "<A>"); print }'
Dynamic regexps¶
ls -l | awk 'BEGIN { digits_regexp = "[[:digit:]]+" } $5 ~ digits_regexp { print }'
ls -l | awk 'BEGIN { digits_regexp = "[[:alpha:]]+" } $4 ~ digits_regexp { print }'
POSIX character classes¶
Class |
Description |
---|---|
[:alnum:] |
Alphanumeric characters |
[:alpha:] |
Alphabetic characters |
[:blank:] |
Space and TAB characters |
[:cntrl:] |
Control characters |
[:digit:] |
Numeric characters |
[:graph:] |
Characters that are both printable and visible 1 |
[:lower:] |
Lowercase alphabetic characters |
[:print:] |
Printable characters 2 |
[:punct:] |
Punctuation characters 3 |
[:space:] |
Space characters 4 |
[:upper:] |
Uppercase alphabetic characters |
[:xdigit:] |
Characters that are hexadecimal digits |