LLMs are already fluent in Python. Instead of handing them a shell and hoping the permission regex holds, give them a Python interpreter with shell-escape paths structurally removed.
counter - counts the repeating elements gives the results in dict format like value:repeated times ...