Rather than overthink it at this stage, just use bufio.Scanner and 
strings.Contains() and see what performance is like. I suspect that for a 
plain string and a large-ish file it will be about as good as it gets.


On Sunday, 8 May 2022 at 09:36:15 UTC+1 Tamás Gulácsi wrote:

> If that "100s of MB" is acceptable to be in memory, then bufio.Scanner 
> with properly sized scanner.Buffer is the easiest and battle tested 
> solution.
>
> If not, then you have to reimplement the same, with a temp file as a 
> buffer: read input, store in file, seeking to the start on each '\n', 
> copying the file to STDOUT when "test" is found.
> Not too hard, but have a few edge cases.
> Const V a következőt írta (2022. május 7., szombat, 22:40:58 UTC+2):
>
>> I need to write a program that reads STDIN and should output every line 
>> that contains a search word "test" to STDOUT. 
>>
>> How I can test that considering the problem is a line can be 100s of MB 
>> long (\n is line end) and tens of MB info is passed to it.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/7497c428-810e-4aad-8c34-86b59134f009n%40googlegroups.com.

Reply via email to