-
-
Save jappy/2012320 to your computer and use it in GitHub Desktop.
#! /bin/sh | |
for x | |
do | |
echo "Converting $x" | |
tr -d '\015' < "$x" > "tmp.$x" | |
mv "tmp.$x" "$x" | |
done |
Usage
Make executable:
chmod +x dos2unix.sh
Apply to filename.txt
./dos2unix.sh filename.txt
Feel free to wildcard the file:
./dos2UNIX.sh [ab]*.txt
Sed Style
from the sed 1liners...
http://www.dbnet.ece.ntua.gr/~george/sed/1liners.txt
TEXT CONVERSION AND SUBSTITUTION:
# IN UNIX ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format
sed 's/.$//' # assumes that all lines end with CR/LF
sed 's/^M$//' # in bash/tcsh, press Ctrl-V then Ctrl-M
sed 's/\x0D$//' # sed v1.5 only
Well, how to conver files in batch?
brew install dos2unix
find . -type f -print0 | xargs -0 dos2unix
Some problem with script...
./dos2unix.sh: line 6: tmp.filename.js: No such file or directory
tr -d '\015' < "$x" > "tmp.$x"
Will script create this tmp file? Will I need to create this tmp file by myself?
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.
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
Credits
Pillaged from http://hintsforums.macworld.com/showthread.php?t=125