Windows batch files do not show consistently in Notepad

I have several files which are Batch or XML files and on some Windows systems they show correctly (i.e. readable) and some others they show with all the lines run together (i.e. unreadable).

I have a suspicion this is because the line break characters are being interpreted differently by the different windows installs.

Has anyone had this themselves and can point me in the correct location to correct ?
LVL 3
AL_XResearchAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
AL_XResearchConnect With a Mentor Author Commented:
Well I have my explanation for the difference - the user who found the difference was using Notepad to look at one copy of the file and Wordpad to look at the other. Wordpad being slightly more intelligent than Notepad interpreted the LF as an EOL.

So that seems to wrap this up. At least I learned that Notepad++ can natively change EOL markers.
0
 
Bill PrewConnect With a Mentor Commented:
I don't think the end of line sequence can be set on Windows (like other localization things can), it always wants a <CR><LF> pair (carriage return, line feed).  A couple of thoughts.

It may be the way the file is delivered to the machines that have issue more than the machines themselves.  Where do these files come from and how are they placed on the Windows machines?

Also, I would suggest you get Notepad++ and use it for viewing and editing these files, it's a much more robust tool than Notepad, and can show a "hex dump" view of the data in the file for better debugging.  https://notepad-plus-plus.org/

Lastly, can you upload one of the files that is reading improperly from one of the Winodws systems it shows as all one line?  That might help us determine what the issue(s) are.

~bp
2
 
AL_XResearchAuthor Commented:
I am afraid I can't upload the files as they are propriety information.

I use ConText programmers editor (an excellent editor - see) and that honours the line-ends but Notepad does not.
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
Bill PrewCommented:
Okay, understand.

Yes, many text editors are smart enough to treat either a single <CR> or a single <LF> as a line termination indicator if they don't see the standard <CR><LF> pair present.

So I guess I'm still where I mentioned earlier.  I expect that the files on those Windows machines are different than on the other Windows machine, with regard to the EOL characters.  If ConText has a HEX view mode that shows all characters including the EOL ones then you could see that.

And if so, then the question becomes what was done differently in placing those files on the different Windows machines, that changed the EOL sequence.  Certainly this is common when FTP from a Unix box is involved, but you haven't mentioned that so I won't assume.

Notepad is not as 'smart' as most text editors, it needs the <CR><LF> pair to behave properly I believe.

~bp
0
 
dbruntonConnect With a Mentor Commented:
On the suspect files it's a matter of replacing the end of lines with a new symbol and then replacing all of the new symbols with CR-LF characters.

For example you'd search for the pairing CR-LF and replace with XXXX
Then LF and replace with XXXX
Then CR and replace with XXXX
Now all of your ends of lines are XXXX and you search for those and replace with the pairing CR-LF.
You need a text editor that can identify and handle these characters.  Possibly UltraEdit https://www.ultraedit.com/support/tutorials_power_tips/ultraedit/multiline_find_replace.html but I'm sure others exist.

Or the dos2unix and unix2dos tools.  See https://sourceforge.net/projects/dos2unix/  These are very useful if you need to convert between the two formats.
0
 
AL_XResearchAuthor Commented:
Bill: This is exactly what I was thinking.

The files are installed / created by third party software installation and quite possibly were originally created or stored on a UNIX box.

I had the same thought about using a hex editor to check the end-of-line terminators. Do you know a good open-source one that can be used commercially ?
0
 
Bill PrewCommented:
It's not fancy, but I have used some of their other tools so picked this up at one point as well.

https://www.funduc.com/fshexedit.htm

There are a number of free options out there, if you want to explore further take a look at this wiki page:

https://en.wikipedia.org/wiki/Comparison_of_hex_editors

~bp
0
 
AL_XResearchAuthor Commented:
I have used Notepad++ and set the 'View | Show Symbol | Show End Of Line' and it confirms that the Batch file must have either been created or FTPed to a Unix system as the end of line char is just a 'LF'.

That still does not explain why sometimes Notepad shows the lines correctly and sometimes with all the lines run together. Maybe when settings in the application change it modifies the batch file but since it is now on a Windows box it uses CR+LF  ?
0
 
dbruntonConnect With a Mentor Commented:
Have you tried running the unix2dos tool I suggested and linked to above?
0
 
AL_XResearchAuthor Commented:
Have you tried running the unix2dos tool I suggested and linked to above?
No I haven't used that tool. I don't want to change the file (or risk changing the reliant software's functionality) - I just wanted to explain why sometimes the lines are run all-together and sometimes appear fine. The suggestion I have given is the only thing I can think of.
0
 
AL_XResearchAuthor Commented:
In actual fact, if I wanted to change the EOL markers, Notepad++ will do this easily from a menu selection.
0
 
Bill PrewCommented:
That still does not explain why sometimes Notepad shows the lines correctly and sometimes with all the lines run together.
Have you also looked at the file with Notepad++ on a system where the line wrapping is handled properly, and if so do you see <CR><LF> as the end of line sequence there?  I have to think you will, and if that is the case then something different is happening in the way the files are created or moved to the different Windows machines.  Hard to guess what that could be without more info, but if you want to detail the creation and distribution of the file that would be a start.

~bp
0
 
AL_XResearchAuthor Commented:
It turned out that it was not a file difference but a mistake on the user's part who identified the issue. However it was useful to know that the EOL markers cannot be changed in Windows by Notepad++ can change the EOL markers in a file.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.