Created
March 19, 2019 15:23
-
-
Save wickkidd/7d9c87d7459b58f1e0a6df71906cb234 to your computer and use it in GitHub Desktop.
I wanted to replace string matches with the output of piped shell commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# python | |
import subprocess | |
import re | |
o = open("some_html_file.out.html","w") | |
data = open("./some_html_file.html").read() | |
def gen_id(match): | |
match = match.group() | |
id = subprocess.getoutput("cat /dev/urandom | env LC_CTYPE=C tr -cd 'a-f0-9' | head -c 4") | |
return f'{match} id="{id}"' | |
o.write(re.sub(r'(<p)', gen_id, data)) | |
o.close() | |
print('done') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment