Aug 4, 2021

How to handle carriage return

Vim - view in binary mode

file rest.py

# rest.py: Python script, ASCII text executable, with very long lines, with CRLF line terminators

vim -b rest.py  # to  view ^M characters


Solution

1) dos2unix rest.py

2) Alternate to dos2unix

sed -i -e "s/\r//g" `cat /tmp/file_changes.txt`

-i: in-place

-e: regular expression

\r: escaped carriage return

/g: replace globally


Git

  • vim .git/config
    • [core]
      • autocrlf = true
      • filemode = false
  • git diff --ignore-space-at-eol > /tmp/complete_diff.txt