package main
import (
"bufio"
"fmt"
"io"
"log"
"os"
"strings"
)
func main() {
r, err := os.Open("data.txt")
if err != nil {
log.Fatal(err)
}
defer r.Close()
s, err := excludeLines(r)
if err != nil {
log.Fatal(err)
}
fmt.Println(s)
}
func excludeLines(r io.Reader) (string, error) {
var lines []string
s := bufio.NewScanner(r)
for s.Scan() {
text := s.Text()
if strings.Contains(text, "^") {
continue
}
lines = append(lines, text)
}
err := s.Err()
if err != nil {
return "", errors.Wrap(err, "Scan")
}
return strings.Join(lines, "\n"), nil
}