Extract matches with a regular expression

Bash

grep -o prints only the matching part, which turns grep into a crude extractor.

grep -oE '[0-9]{1,3}(\.[0-9]{1,3}){3}' access.log | sort -u

# Every email address in a directory:
grep -rhoE '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}' . | sort -u

More in Text Processing

Random picks