awk

Patterns

Regexp Patterns

Patterns can be specified as regular expressions:

/regular expression/ {action}

For example:

echo "user@hostname.com
not an email" | awk '/[^@]+@.+/ {print}'

Produces:

user@hostname.com

Note that an action consisting only of the print statement can be omitted entirely. The above example is equivalent to:

echo "user@hostname.com
not an email" | awk '/[^@]+@.+/'

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow