Last active
May 20, 2016 19:49
-
-
Save sjlxndr/b762ee8dfbb732fc8b3645dec1e56ac4 to your computer and use it in GitHub Desktop.
under current directory, find files with CRLF line termination and convert them to LF line termination
This file contains 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
#!/bin/sh | |
# see comments at https://gist.github.com/sjalex/b762ee8dfbb732fc8b3645dec1e56ac4 for details | |
/bin/find . -type f -execdir sh -c '/usr/bin/file {} | /bin/grep CRLF && /bin/ex {} "+set ff=unix|wq"' \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This finds files under the current directory that have CRLF line termination and uses /bin/ex to convert them to LF line termination. One could just as well use dos2unix in place of the ex command line, but ex is more universally installed than dos2unix and its output is quieter.
Written against the following executable versions:
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
find (GNU findutils) 4.4.2
file-5.04
grep (GNU grep) 2.20
ex (VIM 7.4, Included patches: 1-207, 209-629)