Created
July 6, 2011 08:28
-
-
Save tototoshi/1066827 to your computer and use it in GitHub Desktop.
カレントディレクトリ以下を再帰的にsedしまくる
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 python | |
# -*- coding: utf-8 -*- | |
import sys | |
import os | |
import subprocess | |
def do_sed(fullpath, old, new): | |
sed_script = "s/%s/%s/g" % (old, new) | |
command = ["sed", "-i", fullpath, "-e", sed_script] | |
subprocess.call(command) | |
if __name__ == '__main__': | |
argvs = sys.argv | |
argc = len(argvs) | |
if argc != 3: | |
sys.exit(1) | |
old = argvs[1] | |
new = argvs[2] | |
srcdir = "." | |
for root,dir,files in os.walk(srcdir): | |
for f in files: | |
fullpath = os.path.join(root,f) | |
do_sed(fullpath, old, new) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment