News for hackers. Stuff that matters.
Re:CR+LF Has a Long History by CornCobs on Monday February 07, 2022 @11:34PM (#30254931)
The dos2unix tool is purpose-built for this!
Re:CR+LF Has a Long History by j1elo on Tuesday February 08, 2022 @12:00AM (#30255056)
You are right, that's the best tool to use for the job!

However, as it usually happens with scripts, adding non-coreutils dependencies becomes an issue (now the script needs to check for existence, request users to install if missing, etc...) For this use case which is so well scoped, a single character removal seems enough but in general I totally agree with dos2unix as the better choice.

Re:CR+LF Has a Long History by mananaysiempre on Monday February 07, 2022 @11:55PM (#30255024)
Note that dos2unix and unix2dos do what you expect when used as filters, but overwrite the specified file in place when given a file name. This is a footgun second only to one in pdftotext, arguably, which (unsurprisingly) refuses to work as a filter and (surprisingly) will silently create a matching .txt file when passed a single .pdf as an argument.
Re:CR+LF Has a Long History by spc476 on Tuesday February 08, 2022 @02:17AM (#30255746)
Why is that a footgun? If it just piped the output to stdout, then to convert a file, you then have to

    $ dos2unix file >x
    $ mv x file
In my mind, overwriting the file is the Right Thing.
Re:CR+LF Has a Long History by romwell on Tuesday February 08, 2022 @03:27AM (#30256081)
The Right Thing would be to require an explicit -o <output filename> option to avoid modifying files without getting user's consent first.

Especially because the changes it makes are irreversible (e. g. when a text file has mixed unix/dos line endings).

Re:CR+LF Has a Long History by Josteniok on Monday February 07, 2022 @11:45PM (#30254979)
Or flip (https://ccrma.stanford.edu/~craig/utility/flip/)! I've been carrying this thing around with me for years.