Skip to content

Instantly share code, notes, and snippets.

@nexpr
Created April 25, 2022 13:27
Show Gist options
  • Save nexpr/3e7f105ca7b1d394bb2e9bc317236c1b to your computer and use it in GitHub Desktop.
Save nexpr/3e7f105ca7b1d394bb2e9bc317236c1b to your computer and use it in GitHub Desktop.
CRLFをLFに一括変換

CRLF を LF に一括変換する

引数に glob を指定
shell で展開されないようにクオートで囲む必要あり

python3 crlf2lf.py "**/*.js"
import sys
import glob
for arg in sys.argv[1:]:
for path in glob.glob(arg, recursive=True):
with open(path, "rb") as f:
text1 = f.read().decode()
text2 = text1.replace("\r\n", "\n")
if text1 == text2:
print("SKIP", path)
else:
with open(path, "wb") as f:
f.write(text2.encode())
print("CONV", path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment