Skip to content

Instantly share code, notes, and snippets.

@nrtkbb
Created August 24, 2015 12:18
Show Gist options
  • Save nrtkbb/fce62bce5ab75003a77c to your computer and use it in GitHub Desktop.
Save nrtkbb/fce62bce5ab75003a77c to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import os
import re
import sys
tabs = re.compile(r'^(\t+)')
spaces = ' '
def doit(filepath):
path = os.path.join(os.getcwd(), filepath)
lines = []
with open(path, 'r') as f:
for line in f.readlines():
m = tabs.search(line)
if m:
line = line.replace(m.group(1), spaces*len(m.group(1)))
lines.append(line)
with open(path, 'w') as f:
f.write(''.join(lines))
if __name__ == '__main__':
for line in sys.stdin:
doit(line.strip())
find . -name "*.extention" | /path/to/change_tab_to_space.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment