Solved

Windows batch files do not show consistently in Notepad

Posted on 2016-10-13
13
29 Views
Last Modified: 2016-10-22
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 ?
0
Comment
Question by:AL_XResearch
  • 7
  • 4
  • 2
13 Comments
 
LVL 51

Assisted Solution

by:Bill Prew
Bill Prew earned 250 total points
ID: 41841756
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
 
LVL 3

Author Comment

by:AL_XResearch
ID: 41842114
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
 
LVL 51

Expert Comment

by:Bill Prew
ID: 41842141
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
 
LVL 47

Assisted Solution

by:dbrunton
dbrunton earned 250 total points
ID: 41842692
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
 
LVL 3

Author Comment

by:AL_XResearch
ID: 41842747
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
 
LVL 51

Expert Comment

by:Bill Prew
ID: 41843468
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 3

Author Comment

by:AL_XResearch
ID: 41846410
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
 
LVL 47

Assisted Solution

by:dbrunton
dbrunton earned 250 total points
ID: 41846415
Have you tried running the unix2dos tool I suggested and linked to above?
0
 
LVL 3

Author Comment

by:AL_XResearch
ID: 41846521
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
 
LVL 3

Author Comment

by:AL_XResearch
ID: 41846525
In actual fact, if I wanted to change the EOL markers, Notepad++ will do this easily from a menu selection.
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 41846532
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
 
LVL 3

Accepted Solution

by:
AL_XResearch earned 0 total points
ID: 41846545
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
 
LVL 3

Author Closing Comment

by:AL_XResearch
ID: 41855089
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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This is an explanation of a simple data model to help parse a JSON feed
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now