Remove Control-M symbols from files on Mac

November 24, 2023

Before

$ vi -v file
This is a test^M

Remove Control-M symbols from files on Mac

  1. Using sed command
find . -type f -exec sed -i '' -e 's/\r//g' {} \;
  1. Using dos2unix command
brew install dos2unix
find . -type f -print0 | xargs -0 dos2unix

After

$ vi -v file
This is a test


Profile picture

Written by Yerin Hong who lives in London and works in the UK.