HowTo: Convert Windows-style line endings to Unix-style (and vice versa)

Though there are some tools (e.g. dos2unix) available to convert between DOS/Windows (\r\n) and Unix (\n) line endings, you'd sometimes like to solve this rather simple task with tools available on any linux box you connect to. So, here are some examples - just pick the one that fits you best: Windows to Unix:

perl -pe '$_=~s#\r\n#\n#' < windows.txt [> linux.txt]
sed -r 's/\r$//' windows.txt [> linux.txt]

:set ff=unix

Unix to Windows (do you really want this?)

perl -pe '$_=~s#\n#\r\n#' < linux.txt [> windows.txt]
sed -r 's/$/\r/' linux.txt [> windows.txt]

:set ff=dos

Don't forget to save your file, when you're using vim.