Skip to content

Instantly share code, notes, and snippets.

@tototoshi
Created July 6, 2011 08:28
Show Gist options
  • Save tototoshi/1066827 to your computer and use it in GitHub Desktop.
Save tototoshi/1066827 to your computer and use it in GitHub Desktop.
カレントディレクトリ以下を再帰的にsedしまくる
#!/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