Monday, June 18, 2012

pain of line endings - remove the dos line endings

The pain of \r\n. If your scripts in *nix are giving strange errors, dos line endings might be the issue. The issues of mixing Windows and Linux.


# remove dos char endings from a file
for i in $* 
do
  sed 's/\r//' $i > $i.out && mv $i.out $i
done


Save as script.sh, and run on your troublesome files.
script.sh <files>
e.g. 
script.sh *.sql