[FreeBSD 12.1] There is no pkg or port dos2unix

Hello,
I am searching for pkg or port dos2unix, but it does not exists
Bash:
# whereis dos2unix
dos2unix: 
# whereis unix2dos
unix2dos: /usr/ports/converters/unix2dos
Is it not maintained anymore?
 
If you just need to convert the line endings from DOS (CR+LF) to UNIX (LF only), then tr -d '\r' will do that.
tr -d '\r' < input.txt > output.txt

If you need to convert the character set from DOS (so-called „codepage 437“) to UNIX (commonly UTF-8), then iconv -f cp437 -t utf8 will do that.
iconv -f cp437 -t utf8 input.txt > output.txt

If course, you can combine the two commands. And if you need to do that often, it might be worth to create an alias or a shell function, or even a small script.
Code:
#!/bin/sh -
cat -- "$@" | tr -d '\r' | iconv -f cp437 -t utf8
You could call that script “dos2unix”, for example. ;)

Both tr(1) and iconv(1) are in the FreeBSD base system. There is no need to install an additional port or package.
 
Yes, but tr(1) can not replace in-place? One has to write a small shell script that uses mktemp(1). No problem, though, maybe that's exactly what that port should do. For a newbie it's easier to install a well-tested solution.
 
Yes, but tr(1) can not replace in-place? One has to write a small shell script that uses mktemp(1). No problem, though, maybe that's exactly what that port should do. For a newbie it's easier to install a well-tested solution.
I’m paranoid, so I try to avoid any tools that replace in-place. I prefer to run the conversion, then check that the outcome is what I expect, then remove the original file (or mv(1) the new file over the original file). But that’s just me …

PS: I do have a shell function called “inplace” that can be used with any program that doesn’t support modifications in-place itself. That function keeps a backup of the original file (with extension “.BAK”). So I can write inplace iconv ... file.txt, for example.
 
PS: I do have a shell function called “inplace” that can be used with any program that doesn’t support modifications in-place itself. That function keeps a backup of the original file (with extension “.BAK”). So I can write inplace iconv ... file.txt, for example.
Please append that to the thread Useful Scripts, and/or even better, file a bug report + patch to /usr/share/examples/csh/dot.cshrc (& tcsh/complete.tcsh and/or similar for other shells (e.g. shells/bash-completion).
 
To convert an \r\n file to \n, I usually open up the file in vi and type:

Code:
:%s/^M//g

The ^M is hold ctrl, press v, press m then release ctrl.
 
Back
Top