I would like to find string in a very big txt file (app. 20GB), and print the whole line and not just a string. I would also like to write that line in a new txt file.
Till now I only can search for a string and get True or False result. Can you please help me, I am really lost and do not know how to finalize it.
package main
import (
"fmt"
"io/ioutil"
"os"
"strings"
)
func main() {
var text string
fmt.Print("Enter string: ")
fmt.Scanln(&text)
b, err := os.Open("output.txt")
content, err := ioutil.ReadAll(b)
if err != nil {
panic(err)
}
s := string(content)
fmt.Println(strings.Contains(s, text))
// 1. how to search for string and print whole line?
// 2. how to write that line in new txt file?
}
TIA