I'm trying to get more experience with Go by writing a program that takes input from a .txt file, then sorts each string alphabetically and prints each one out with it's corresponding line number. Right now I'm having a problem where my program is only printing out the first string per line when I pass it my input.txt file
package main
import "fmt"
import "regexp"
import "bufio"
import "log"
import "os"
import "strings"
func main() {
var i int = 0 //counter for loop
var words1 string
scanner := bufio.NewScanner(os.Stdin)
//holdWords := make(map[string]int)
//Loop through the txt doc and cleanup the lines of strings
for scanner.Scan(){
i=i+1
words1=scanner.Text(); //get the text from line
words1=strings.TrimSpace(words1) //trim the trailing and leading whitespace
reg, err:= regexp.Compile("^[a-zA-Z]+") //regex to look for letters/spaces
if err != nil{
log.Fatal(err)
}
fmt.Println(reg.FindString(words1))//just testing to see if it prints correct values
}
}