Programming Tips - bash: unix2dos command

Date: 2020oct22 Language: bash Q. bash: unix2dos command A. Here's simple bash script that converts a file from Linux/Unix to DOS/Windows line endings in place. Instead of tr I used perl, taking advantage that it knows how to read lines. I read each line, remove the line ending then print CRLF. /usr/local/bin/u2d:
#!/usr/bin/bash set -euo pipefail for I in $*; do if [ -f $I ]; then cp $I $I.old perl -e 'while(<STDIN>) { print chomp($_); print "\r\n"; }' < $I.old > $I rm $I.old fi done
Or you can install the unix2dos package