https://github.com/yottahmd/grep
grep utility like the grep command in Unix/Linux.
https://github.com/yottahmd/grep
golang-library grep
Last synced: 3 months ago
JSON representation
grep utility like the grep command in Unix/Linux.
- Host: GitHub
- URL: https://github.com/yottahmd/grep
- Owner: yohamta
- License: mit
- Created: 2022-08-26T02:17:09.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-09-09T06:53:08.000Z (about 3 years ago)
- Last Synced: 2024-06-20T19:27:43.774Z (over 1 year ago)
- Topics: golang-library, grep
- Language: Go
- Homepage:
- Size: 13.7 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# grep
[](https://codecov.io/gh/yohamta/grep)
[](https://pkg.go.dev/github.com/yohamta/grep)The grep searches given pattern in a given file and returns matched lines, like the grep command in Unix/Linux.
## Usage
```go
import "github.com/yohamta/grep"
opts := &grep.Options{
IsRegexp: true,
Before: 2,
After: 2,
}matches, err := grep.Grep("target_file.txt", fmt.Sprintf("(?i)%s", pattern), opts)
for _, m := range matches {
println(fmt.Sprintf("Matched Line: %s", m.Line))
println(fmt.Sprintf("Line Number: %d", m.LineNumber))
println(fmt.Sprintf("Start Line: %d", m.StartLine))
}
```## Custom Matcher
You can implement the Matcher interface and pass it through the `grep.Option.Mather` field.
```go
// Matcher is the interface for matching lines.
type Matcher interface {
// Match returns true if the given line matches.
Match(line string) bool
}
```# License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details