Using Raku (formerly known as Perl_6)
~$ cat unix2dos.raku
my $fh1 = open $*IN, :r;
#below use :w (write-only) or :x (:x write-only :exclusive i.e. 'no-clobber')
my $fh2 = open $*OUT, :x, nl-out => "\r\n";
for $fh1.lines() { $fh2.put($_) };
$fh1.close;
$fh2.close;
Save the above file to a script (e.g. "unix2dos.raku"), add a shebang line and make it executable--or simply call it at the command line:
~$ raku unix2dos.raku < ends_with_LF.txt > ends_with_CRLF.txt
Example Input showing Unix line endings with 0a
per line:
~$ jot -w '%d' 5 | hexdump -C
00000000 31 0a 32 0a 33 0a 34 0a 35 0a |1.2.3.4.5.|
0000000a
Example Output (adds Raku script) to generate DOS line endings with 0d 0a
per line:
~$ jot -w '%d' 5 | raku unix2dos.raku | hexdump -C
00000000 31 0d 0a 32 0d 0a 33 0d 0a 34 0d 0a 35 0d 0a |1..2..3..4..5..|
References:
https://docs.raku.org/language/newline.html
https://raku.org
Example Source:
https://unix.stackexchange.com/a/742732/227738
\r\n
added to the last line of the file, even if none exists? See this Vim question: unix.stackexchange.com/q/263869/227738