# [FreeBSD 12.1] There is no pkg or port dos2unix



## taydo (Aug 26, 2020)

Hello,
I am searching for pkg or port dos2unix, but it does not exists

```
# whereis dos2unix
dos2unix: 
# whereis unix2dos
unix2dos: /usr/ports/converters/unix2dos
```
Is it not maintained anymore?


----------



## diizzy (Aug 26, 2020)

The port "installs" dos2unix





						[ports] Contents of /head/converters/unix2dos/Makefile
					






					svnweb.freebsd.org


----------



## Mjölnir (Aug 26, 2020)

You can also use converters/dosunix or converters/recode.  Maybe other ports in /usr/ports/converters offer this functionality, too.


----------



## mark_j (Aug 26, 2020)

taydo said:


> Hello,
> I am searching for pkg or port dos2unix, but it does not exists
> 
> ```
> ...


Just use `tr`


----------



## taydo (Aug 26, 2020)

diizzy said:


> The port "installs" dos2unix
> 
> 
> 
> ...



Thank Sir,
This is not on my machine's ports [FreeBSD 12.1] even though having portsnap update

@all: thanks for precious suggestion of alternatives, I will use dosunix (with its 3 utilities)


----------



## Mjölnir (Aug 26, 2020)

The standard file(1) utility tells you if it's a DOS text file (no need for an extra utility).


----------



## Mjölnir (Aug 26, 2020)

Related: in addition, converters/recode (GNU) & converters/bsdconv can convert between various charsets.


----------



## olli@ (Aug 26, 2020)

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.

```
#!/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.


----------



## Mjölnir (Aug 26, 2020)

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.


----------



## olli@ (Aug 26, 2020)

mjollnir said:


> 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.


----------



## Mjölnir (Aug 26, 2020)

olli@ said:


> 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).


----------



## olli@ (Aug 26, 2020)

mjollnir said:


> Please append that to the thread _Useful Scripts_


Done.


----------



## kpedersen (Aug 26, 2020)

To convert an \r\n file to \n, I usually open up the file in vi and type:


```
:%s/^M//g
```

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


----------

