Real-world examples of gnaw usage for common development tasks.
Monitor application logs for errors in real-time:
# Monitor errors in real-time
tail -f /var/log/app.log | gnaw --stream "ERROR"
# Count errors by hour
gnaw -c "ERROR" /var/log/app-$(date +%Y-%m-%d).log
# Find errors with context
gnaw -C 3 "ERROR" /var/log/app.log
Analyze performance metrics from logs:
# Find slow queries
gnaw "slow query" /var/log/db.log
# Monitor response times
gnaw -E "response_time:[0-9]{4,}" /var/log/app.log
# Find memory issues
gnaw -i "out of memory\|memory leak" /var/log/app.log
Detect security issues in logs:
# Find failed login attempts
gnaw -i "authentication failed\|login failed" /var/log/auth.log
# Monitor for suspicious activity
gnaw -E "failed.*attempts.*[0-9]{3,}" /var/log/security.log
# Check for SQL injection attempts
gnaw -i "union.*select\|drop.*table" /var/log/web.log
Ensure code quality standards:
# Find TODO comments
gnaw -n "TODO" src/
# Check for debug statements
gnaw -l "console\.log\|print\|debugger" src/
# Find hardcoded credentials
gnaw -i "password.*=\|api_key.*=\|secret.*=" src/
Analyze code documentation:
# Find undocumented functions
gnaw -l "def " src/ | gnaw -v "docstring\|@doc"
# Check for missing docstrings
gnaw -A 2 "def " src/ | gnaw -v "docstring"
# Find example code
gnaw -i "example\|usage\|demo" docs/
Analyze code dependencies:
# Find import statements
gnaw -n "import " src/
# Check for unused imports
gnaw -l "import " src/ | gnaw -v "used"
# Find external dependencies
gnaw -E "from.*import\|require.*" src/
Find files based on content:
# Find configuration files
gnaw -l "config\|settings" .
# Find test files
gnaw -l "test\|spec" .
# Find documentation files
gnaw -l "readme\|doc\|guide" .
Analyze file contents:
# Find large files
find . -type f -size +10M | gnaw -l "large file"
# Find binary files
file * | gnaw -i "binary\|executable"
# Find empty files
find . -type f -empty | gnaw -l "empty file"
Monitor system health:
# Check disk usage
df -h | gnaw -E "[0-9]{2,}%"
# Monitor memory usage
free -h | gnaw -E "[0-9]+G"
# Check running processes
ps aux | gnaw -i "python\|node\|java"
Manage system services:
# Check service status
systemctl status | gnaw -i "active\|failed"
# Monitor service logs
journalctl -u nginx | gnaw "error\|warning"
# Find service configurations
gnaw -l "service\|daemon" /etc/systemd/system/
Integrate with Git workflows:
# Check for sensitive data in commits
git log --oneline | gnaw -i "password\|secret\|key"
# Find large files in history
git log --stat | gnaw -E "[0-9]+ files changed"
# Monitor commit messages
git log --oneline | gnaw -i "fix\|bug\|error"
Monitor build processes:
# Check build logs
gnaw -i "error\|warning\|failed" build.log
# Monitor compilation
gnaw -i "compiling\|building\|linking" build.log
# Find build artifacts
gnaw -l "\.o\|\.so\|\.a" build/
Analyze CSV data:
# Find specific values
gnaw -F "specific_value" data.csv
# Count occurrences
gnaw -c "pattern" data.csv
# Extract specific columns
gnaw -o "column_name.*" data.csv
Process JSON data:
# Find specific keys
gnaw -o "\"key\":.*" data.json
# Extract values
gnaw -o "\"value\":.*" data.json
# Find nested objects
gnaw -E "\{[^}]*\}" data.json
Process XML data:
# Find specific tags
gnaw -o "<tag>.*</tag>" data.xml
# Extract attributes
gnaw -o "attribute=\".*\"" data.xml
# Find nested elements
gnaw -E "<[^>]*>.*</[^>]*>" data.xml
Analyze network logs:
# Find failed connections
gnaw -i "connection failed\|timeout" /var/log/network.log
# Monitor bandwidth usage
gnaw -E "bytes.*[0-9]{6,}" /var/log/network.log
# Check for security issues
gnaw -i "blocked\|denied\|forbidden" /var/log/firewall.log
Monitor API endpoints:
# Find API errors
gnaw -E "HTTP/[0-9]+.*[4-5][0-9][0-9]" /var/log/api.log
# Monitor response times
gnaw -E "response_time:[0-9]+ms" /var/log/api.log
# Check for rate limiting
gnaw -i "rate limit\|throttle" /var/log/api.log
# Find email addresses
gnaw -E "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}" data.txt
# Find IP addresses
gnaw -E "([0-9]{1,3}\.){3}[0-9]{1,3}" data.txt
# Find URLs
gnaw -E "https?://[^\s]+" data.txt
# Analyze multiple log files
gnaw -r "ERROR" /var/log/
# Compare different time periods
gnaw "ERROR" /var/log/app-2023-03-15.log
gnaw "ERROR" /var/log/app-2023-03-16.log
# Find patterns across different file types
gnaw -r "pattern" --type log,txt,csv .
#!/bin/bash
# Generate daily error report
DATE=$(date +%Y-%m-%d)
ERROR_COUNT=$(gnaw --raw -c "ERROR" /var/log/app-$DATE.log)
WARN_COUNT=$(gnaw --raw -c "WARN" /var/log/app-$DATE.log)
echo "Daily Report - $DATE"
echo "Errors: $ERROR_COUNT"
echo "Warnings: $WARN_COUNT"
if [ "$ERROR_COUNT" -gt 10 ]; then
echo "High error count detected!"
gnaw -C 2 "ERROR" /var/log/app-$DATE.log
fi