Created
June 16, 2021 15:22
-
-
Save thanksshu/03d74013f892840877b1a340f0342aac to your computer and use it in GitHub Desktop.
Convert line endings in-place (Windows to Linux/Unix)
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
# replacement strings | |
WINDOWS_LINE_ENDING = b'\r\n' | |
UNIX_LINE_ENDING = b'\n' | |
# relative or absolute file path, e.g.: | |
file_path = r'file_path' | |
with open(file_path, 'rb') as fs: | |
content = fs.read() | |
content = content.replace(WINDOWS_LINE_ENDING, UNIX_LINE_ENDING) | |
with open(file_path, 'wb') as open_file: | |
open_file.write(content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment