Last active
February 4, 2023 07:17
-
-
Save briceburg/491ab5d4ccd188abae8ce48bf937b85a to your computer and use it in GitHub Desktop.
Python multiple replacements using reduce
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
#!/usr/bin/env python3 | |
import sys | |
import functools | |
for line in map(str.rstrip, sys.stdin): | |
repls = ('prod', 'production'), ('sdlc', 'staging'), ('sandbox', 'development') | |
print("terraform state mv %s %s" % (line, functools.reduce(lambda a, kv: a.replace(*kv), repls, line))) |
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
# the proverbial followup | |
while IFS="" read -r p || [ -n "$p" ] | |
do | |
eval "$p" | |
done < py-output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment