Skip to content

Instantly share code, notes, and snippets.

@sjlxndr
Last active May 20, 2016 19:49
Show Gist options
  • Save sjlxndr/b762ee8dfbb732fc8b3645dec1e56ac4 to your computer and use it in GitHub Desktop.
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
#!/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"' \;
@sjlxndr
Copy link
Author

sjlxndr commented May 20, 2016

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)

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