Mixture of line endings in a single file, how to correct it

For general web development questions that are not specifically related to CSS HTML Validator. This includes (but is not limited to) general HTML, CSS, Accessibility, JavaScript, and SEO questions.
Post Reply
User avatar
MikeGale
Rank VI - Professional
Posts: 726
Joined: Mon Dec 13, 2004 1:50 pm
Location: Tannhauser Gate

Mixture of line endings in a single file, how to correct it

Post by MikeGale »

I periodically find that I'm working on a file with mixed line endings in it.

(I've not checked thoroughly, I think they arise when somebody else touches a file and I use a diff tool to merge some of their lines with my own OR somebody else manufactures it.)

I'm interested in how other people "fix" such files to have a single form of line end.
User avatar
Albert Wiersch
Site Admin
Posts: 3783
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Mixture of line endings in a single file, how to correct it

Post by Albert Wiersch »

There is an old 'Convert Text File Format' tool in CSS HTML Validator that might help. You could try it and see how it does, but keep backups in case it doesn't work as expected or there is an issue with character encoding in the converted files.

You can choose what line ending you want in the 'Tools' page of the Validator Engine Options... then choose 'Tools->Convert Text File Format' and choose the file you want to use the tool on.

Wouldn't it have been great if everyone has just used the same line endings from the beginning (PC, Mac, Unix, etc.) and this was never an issue? :D
Albert Wiersch, CSS HTML Validator Developer • Download CSS HTML Validator FREE Trial
User avatar
MikeGale
Rank VI - Professional
Posts: 726
Joined: Mon Dec 13, 2004 1:50 pm
Location: Tannhauser Gate

Re: Mixture of line endings in a single file, how to correct it

Post by MikeGale »

Yep I had the dubious pleasure of using a Teletype machine many years ago. I remember how carriage return and line feed were distinct "commands".

It looks deliberate. With two symbols there are 3 ways of doing it (barring LFCR) and we've got all of them.

That tool is a great way of doing it. (It can be setup to take a backup, so no need to do that manually.)

I've concluded that a good approach is to harmonise the line-breaks in the tool where you identify the problem.

In my diff tool (Beyond Compare) I get a great indication of what's going on. At the top it indicates whether line-breaks are "mixed" and, if I show whitespace, it uses distinct symbols for different newlines, so I can see where it occurs.

Image

The image doesn't appear, it's at https://ibb.co/9hPQhDW
Post Reply