Added support for printing specific match indices ('-m' and '-p' flags combined)

master
Aadhavan Srinivasan 3 weeks ago
parent 13ca954072
commit 8a0586d107

@ -705,8 +705,14 @@ func main() {
if !(*multiLineFlag) {
fmt.Fprintf(out, "Line %d:\n", lineNum)
}
for _, idx := range matchIndices {
fmt.Fprintf(out, "%s\n", idx.toString())
for i, m := range matchIndices {
// Only print a match if:
// a. We are _not_ printing just one match
// OR
// b. We _are_ printing just one match, and this is that match
if !matchNumFlagEnabled || (i+1) == *matchNum { // Match indexes start from 1; loop counter starts from 0
fmt.Fprintf(out, "%s\n", m.toString())
}
}
err := out.Flush()
if err != nil {

Loading…
Cancel
Save