a single-purpose unix filter that reads stdin, matches a target pattern against each line, and writes matches to stdout.
# arch linux (aur)
paru -S snag-bin
# from crates.io
cargo install snag-cli
# from source
git clone https://github.com/programmersd21/snag.git
cd snag && cargo install --path .snag <target>
<stream> | snag <target>| target | description | example |
|---|---|---|
ip |
ipv4 and ipv6 addresses | echo "host 10.0.0.1" | snag ip → 10.0.0.1 |
url |
http:// and https:// urls |
echo "see https://example.com" | snag url → https://example.com |
num |
standalone integers | echo "code: 404 retries: 2" | snag num → 404, 2 |
hash |
hex strings 7–64 chars (sha, md5) | echo "commit a1b2c3d" | snag hash → a1b2c3d |
path |
absolute unix file paths | echo "at /var/log/syslog" | snag path → /var/log/syslog |
email |
email addresses | echo "to user@example.com" | snag email → user@example.com |
.<key> |
top-level field from ndjson stream | echo '{"id": 42}' | snag .id → 42 |
:<n>, /<n>, ,<n> |
1-indexed column delimiter split | echo "root:x:0" | snag :1 → root |
<pre>{}<post> |
literal template with wildcard capture | echo "id=[123]" | snag 'id=[{}]' → 123 |
<regex> |
raw regex fallback (group 1 or match) | echo "port=8080" | snag 'port=(\d+)' → 8080 |
# extract unique ips from server logs
tail -n 1000 /var/log/nginx/access.log | snag ip | sort -u
# extract commit hashes from git log
git log --oneline | snag hash
# extract json fields from an ndjson stream
docker events --format '{{json .}}' | snag .action
# column extraction without awk syntax
cat /etc/passwd | snag :1
# wildcard capture with literal auto-escaping
kubectl get pods | snag 'pod/{}-'- delimiter splitting: column mode (
:n,/n,,n) performs a literal byte split without csv quote parsing. - utf-8 handling: invalid byte sequences are replaced per line with the unicode replacement character (
u+fffd) without aborting. - exit codes: returns
0on clean runs (including 0 matches) and1on invalid arguments or uncompilable patterns.
