Filter text by keywords – Getting help

hi community,

I am trying to filter a text by keyword with golang. Basically, what I’m executing:

package main

import (
	"fmt"
	"os/exec"
)

func branches() {
	out, err := exec.Command("git", "branch", "-a", "--sort=-committerdate", "--column", "--format="%(committerdate)%09%(refname:short)"").Output()

	if err != nil {
		// log.Fatal(err)
		fmt.Println("Couldn't find any branches in the repository")
	}

	str1 := string(out)

	fmt.Println(str1)
}

func main() {
	fmt.Printf("1. CHECK ALL BRANCHES: ")
	branches()
}

and get:

go run main.go
1. CHECK ALL BRANCHES: 'Mon Oct 3 12:20:53 2022 +0000	master'
'Mon Oct 3 12:20:53 2022 +0000	origin/HEAD'
'Mon Oct 3 12:20:53 2022 +0000	origin/master'
'Mon Oct 3 12:12:01 2022 +0000	origin/release/v1'
'Wed Apr 27 06:26:22 2022 +0000	origin/release/v2'
'Tue Feb 15 14:46:55 2022 +0000	origin/release/v3'
'Mon May 24 16:05:45 2021 +0300	origin/release-v1'
'Tue Oct 6 14:43:56 2020 +0300	origin/release-v1.0.0'

The goal is to get all lines that are older than 2022, so 2021, 2020, 2019, etc and display those lines in the command line/terminal.

Maybe someone can help?

Br,


Leave a Comment