Creating a single line text file from DOS
Friday, April 25th, 2008I recently had the need to write a batch file that wrote a single line of text to a file for processing by an application. I used the DOS command ‘ECHO’ and directed the output to file, however this wasn’t working and after a bit of troubleshooting I discovered that the resulting file couldn’t end with a new line.
At first I thought this could be a DOS/UNIX issue and ran a simple command-line application (DOS2UNIX) to convert my newlines to a format suitable for Unix based machines. Unfortunately this wasn’t good enough and I needed to find a way of removing the new line from my file. Eventually I found another simple application named CHANGE, which allows you to find and replace characters within files from the command line.
As the characters I needed to replace were a space and the carriage return/line feed I needed to be able to specify the characters as bytes. CHANGE.COM is able to do this, so the following command enabled me to remove the trailing new line:
CHANGE MYFILE.TXT 32,13,10 ""
The CHANGE.COM file can be downloaded from here.
Update: I found a Windows Script that will remove the line here, but have instead written a script that replaces the batch file.