A simple command-line tool written in Rust that searches for text patterns in files, similar to the grep utility.
- Case-sensitive and case-insensitive search
- File content searching
- Environment variable configuration
- Error handling with informative messages
Make sure you have Rust and Cargo installed on your system. Then:
git clone [your-repository-url]
cd minigrep
cargo build --release
The compiled binary will be available at target/release/minigrep.exe
- Download
minigrep.exe
- (Optional) Add the folder containing minigrep.exe to your system PATH
- Right-click on 'This PC' or 'My Computer'
- Click 'Properties'
- Click 'Advanced system settings'
- Click 'Environment Variables'
- Under 'System Variables', find and select 'Path'
- Click 'Edit'
- Click 'New'
- Add the folder path containing minigrep.exe
- Click 'OK' on all windows
minigrep.exe [search_query] [file_path]
-
search_query
: The text pattern you want to find- Can be a single word or multiple words in quotes
- Case-sensitive by default
- Examples:
minigrep.exe hello file.txt # Searches for "hello" minigrep.exe "hello world" file.txt # Searches for "hello world"
-
file_path
: The path to the file you want to search in- Can be relative or absolute path
- Examples:
minigrep.exe hello .\docs\file.txt # Relative path minigrep.exe hello C:\Users\docs\file.txt # Absolute path
# Case-insensitive search
set IGNORE_CASE=1
minigrep.exe to poem.txt
# Case-insensitive search
$env:IGNORE_CASE=1; .\minigrep.exe to poem.txt
-
Basic search:
minigrep.exe "function" src\main.rs
Finds all lines containing "function" in main.rs
-
Case-insensitive search in multiple files:
# PowerShell $env:IGNORE_CASE=1; Get-ChildItem *.txt | ForEach-Object { .\minigrep.exe "error" $_.Name }
-
Search in a specific directory:
minigrep.exe "TODO" .\src\*.rs
- 0: Successful execution
- 1: Error occurred (invalid arguments, file not found, etc.)
Common error messages and their solutions:
-
"Problem parsing arguments":
- Ensure you provided both search query and file path
- Check if file path is correct
- Enclose multi-word queries in quotes
-
"Application error":
- Verify file exists and you have read permissions
- Check if file content is valid UTF-8
- Ensure sufficient system memory
-
"'minigrep' is not recognized as an internal or external command":
- Make sure you're in the correct directory containing minigrep.exe
- Or add the directory to your PATH (see Installation section)
- Use complete path to executable:
C:\path\to\minigrep.exe
src/main.rs
: Entry point of the applicationsrc/lib.rs
: Core functionality implementationConfig
: Handles program configuration and argument parsingrun
: Main program logicsearch
: Case-sensitive search implementationsearch_case_insensitive
: Case-insensitive search implementation
Run the test suite with:
cargo test
For verbose output including passed tests:
cargo test -- --show-output
The test suite includes:
- Case-sensitive search functionality
- Case-insensitive search functionality
- Configuration parsing
Feel free to submit issues and pull requests.
- Clone the repository
- Install Rust and Cargo
- Run tests to ensure everything works
- Create a new branch for your changes
- Submit a pull request
[MIT]
[fox5352]christopher vos