For finding specific logs from the docker logs, I am using the grep with docker logs as below
docker logs -f docker_container 2>&1 | grep "KafkaRecordGenerator:197"
Which is giving the correct result in the console. I need to redirect these logs to a text file. For that, I used the below command
docker logs -f docker_container 2>&1 | grep "KafkaRecordGenerator:197" >> test.txt
Here the new file test.txt is created but the output is not redirected to the test.txt file. How to redirect the docker logs with grep command to a text file?