Get up and running with gnaw in minutes. This guide covers the most common use cases and commands.
brew tap 10printhello/gnaw
brew install gnaw
git clone https://github.com/10printhello/gnaw.git
cd gnaw
cargo build --release
sudo mv target/release/gnaw /usr/local/bin/
Search for a pattern in a file:
gnaw "ERROR" test.log
4: 2023-03-15 12:34:58,789 ERROR django.request: Internal Server Error: /api/v1/data/
Search through directories:
gnaw -r "pattern" ./logs/
Get just the count of matching lines:
gnaw -c "ERROR" test.log
Use natural language to describe your search:
gnaw --chat "Find all lines containing the word ERROR in any .log file in the logs directory"
Searching for error messages in log files...
Found 3 matches in 2 files:
- logs/app.log:2 matches
- logs/error.log:1 match
See what command would be generated without executing:
gnaw --chat "Show me lines with WARNING in server.log" --dry-run
The most powerful feature of gnaw is its AI-powered semantic search.
First, build an index of your codebase:
gnaw agent index build
Search for code by meaning, not just text:
# Find functions that handle authentication
gnaw agent ask "authentication functions"
# Find error handling patterns
gnaw agent ask "error handling" --type rs
# Search in specific directory
gnaw agent ask "database queries" --dir src/db
Query: authentication functions
→ src/auth.rs (score: 0.95)
Lines 15-25
• Function definition matches query
• Contains authentication keywords
• High semantic similarity
pub fn authenticate_user(token: &str) -> Result<User, AuthError> {
// Authentication logic here
}
Get structured output for programmatic consumption:
gnaw --json "ERROR" test.log
{
"search_term": "ERROR",
"time_taken": "0.123s",
"results": [
{
"file_name": "logs/app.log",
"line_number": 42,
"line": "2023-03-15 12:34:58,789 ERROR django.request: Internal Server Error: /api/v1/data/"
}
]
}
# Show 3 lines after each match
gnaw -A 3 "ERROR" test.log
# Show 1 line before each match
gnaw -B 1 "ERROR" test.log
```
# Show only filenames without matches
gnaw -L "pattern" ./logs/
# Show line numbers
gnaw -n "pattern" file.txt
```
# Invert match (show non-matching lines)
gnaw -v "pattern" file.txt
# Count only
gnaw -c "pattern" file.txt
```