Skip to content

Latest commit

 

History

3 提交

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

仓库 files navigation

snag

modern stream pattern extractor

crates.io aur license: mit ci

snag demo

a single-purpose unix filter that reads stdin, matches a target pattern against each line, and writes matches to stdout.

install

# 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 .

usage

snag <target>
<stream> | snag <target>

targets

target description example
ip ipv4 and ipv6 addresses echo "host 10.0.0.1" | snag ip10.0.0.1
url http:// and https:// urls echo "see https://example.com" | snag urlhttps://example.com
num standalone integers echo "code: 404 retries: 2" | snag num404, 2
hash hex strings 7–64 chars (sha, md5) echo "commit a1b2c3d" | snag hasha1b2c3d
path absolute unix file paths echo "at /var/log/syslog" | snag path/var/log/syslog
email email addresses echo "to user@example.com" | snag emailuser@example.com
.<key> top-level field from ndjson stream echo '{"id": 42}' | snag .id42
:<n>, /<n>, ,<n> 1-indexed column delimiter split echo "root:x:0" | snag :1root
<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

examples

# 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/{}-'

behavior

  • 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 0 on clean runs (including 0 matches) and 1 on invalid arguments or uncompilable patterns.

license

mit

关于

modern stream pattern extractor

Resources

Contributing

安全 policy

Stars

3 stars

关注者

1 watching

复刻s

发布

Sponsor this project

贡献者

Languages