Skip to content

Instantly share code, notes, and snippets.

@jappy
Created March 10, 2012 18:03
Show Gist options
  • Save jappy/2012320 to your computer and use it in GitHub Desktop.
Save jappy/2012320 to your computer and use it in GitHub Desktop.
Shell script to convert files with CRLF to LF (Mac/Linux)
#! /bin/sh
for x
do
echo "Converting $x"
tr -d '\015' < "$x" > "tmp.$x"
mv "tmp.$x" "$x"
done
@uded
Copy link

uded commented Dec 13, 2018

brew install dos2unix
find . -type f -print0 | xargs -0 dos2unix

@Muskos
Copy link

Muskos commented Nov 27, 2019

Some problem with script...
./dos2unix.sh: line 6: tmp.filename.js: No such file or directory

@jappy
Copy link
Author

jappy commented Nov 27, 2019 via email

@Muskos
Copy link

Muskos commented Nov 28, 2019

tr -d '\015' < "$x" > "tmp.$x"
Will script create this tmp file? Will I need to create this tmp file by myself?

@wirekang
Copy link

tr -d '\015' < "$x" > "tmp.$x" Will script create this tmp file? Will I need to create this tmp file by myself?

This script makes tmp file and overwrite original file. You don't need to do anything.

@blacknred0
Copy link

Thanks for sharing this!!!!

I was having some issues with the tmp file not being found. I ended up contacting the string and then run the code. Here is what I ended up doing in the end.

for x
do
    echo "Converting $x"
    temp_file+="tmp."$x
    tr -d '\015' < "$x" > temp_file
    mv temp_file "$x"
done

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