People usually integrate the stuff they ask here, into their own scripts.
For sure you need protections, but there are many types of protection you could apply and he didnt ask for that.
I just showed one way of doing it.

And I didnt know the filter command was able to do that.
Looks quite efficient indeed, glad you demonstrated that.