Skip to content

Instantly share code, notes, and snippets.

@simryang
Created February 25, 2025 06:33
Show Gist options
  • Save simryang/b717b45c05181581dbf6cfcbf1d5a412 to your computer and use it in GitHub Desktop.
Save simryang/b717b45c05181581dbf6cfcbf1d5a412 to your computer and use it in GitHub Desktop.
find DOS line-ended files and convert them into UNIX line-ended
#!/usr/bin/env bash
if ! command -v fromdos > /dev/null 2>&1; then
sudo apt update && sudo apt install -y tofrodos
fi
grep --exclude-dir=".git" -URIl ^M . | xargs fromdos
@simryang
Copy link
Author

grep options help:

  • -I
    • exclude binary
  • -U
    • consider line-ending instead of stripping them away by default
  • -R
    • recursive
  • -l
    • list only the filenames and not the matching lines
  • --exclude-dir=".git"
    • ignore directory ".git"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment