Skip to content

Instantly share code, notes, and snippets.

@thanksshu
Created June 16, 2021 15:22
Show Gist options
  • Save thanksshu/03d74013f892840877b1a340f0342aac to your computer and use it in GitHub Desktop.
Save thanksshu/03d74013f892840877b1a340f0342aac to your computer and use it in GitHub Desktop.
Convert line endings in-place (Windows to Linux/Unix)
# 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