How to use regular expressions in awk?
Hey Richard
To use regular expressions in awk, utilize the ~ operator:
-
awk '/pattern/ {print $0}' file- prints lines that match the pattern. -
awk '!/pattern/ {print $0}' file- prints lines that don’t match the pattern. -
awk '$1 ~ /pattern/ {print $2}' file- prints the second field where the first field matches the pattern.
Replace pattern with your desired regex.