Export data to rsc file

Hi I have some troubles with solving this situation. I need to export data from mangle rules (amounts of Bytes and Packets) to a file. I am beginner in scripting i am doing it for first time, so I deeply appreciate every advice. Thank you.
mangle.JPG

/ip firewall mangle print stats file=stats

It will generate a human readable txt file. If you want to parse these numbers in software, api is a better solution (command /ip/firewall/mangle/print gives you bytes and packets).