1#! /usr/bin/env python3 2"Replace CRLF with LF in argument files. Print names of changed files." 3 4import sys, os 5 6def main(): 7 for filename in sys.argv[1:]: 8 if os.path.isdir(filename): 9 print(filename, "Directory!") 10 continue 11 with open(filename, "rb") as f: 12 data = f.read() 13 if b'\0' in data: 14 print(filename, "Binary!") 15 continue 16 newdata = data.replace(b"\r\n", b"\n") 17 if newdata != data: 18 print(filename) 19 with open(filename, "wb") as f: 20 f.write(newdata) 21 22if __name__ == '__main__': 23 main() 24