replace 200 lines of python with a unix pipeline