Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

add a carriage return to a text file

4,923 views
Skip to first unread message

Ralf Meuser

unread,
Aug 11, 2004, 11:27:30 AM8/11/04
to
Hi there

I create a small batch file wich will merge some textfiles
type %1 >> %2

but some textfile don't end with a carriage return and the last line of one
file will by append with the first line of the next file.

How can I add an
carriage return or a line feed ?

Thanks in advance

Ralf


foxidrive

unread,
Aug 11, 2004, 11:40:58 AM8/11/04
to

echo.>>file.txt

You will be left with the problem of some files ending in a blank line, and
some not.

Richard Bonner

unread,
Aug 12, 2004, 1:52:21 PM8/12/04
to
foxidrive wrote:
> On Wed, 11 Aug 2004 17:27:30 +0200, Ralf Meuser wrote:

> > I created a small batch file wich will merge some textfiles


> > type %1 >> %2
> >
> > but some textfile don't end with a carriage return and the last line
> > of one file will by append with the first line of the next file.
> >

> > How can I add a carriage return or a line feed ?

> echo.>>file.txt

> You will be left with the problem of some files ending in a blank line, and
> some not.

*** I don't think that is a big problem.


For Ralf. Try this. It will add a blank line to each text file name you
type at the command line, and them combine them. It is untested.

:: COMBINE.bat
:: Adds a Blank Line to up to Five .txt Files
:: Combines up to Five .txt Files
::
@ECHO OFF

FOR %%T in (%1.TXT %2.TXT %3.TXT %4.TXT %5.TXT) DO ECHO. >> %T
COPY %1.TXT + %2.TXT + %3.TXT + %4.TXT + %5.TXT COMBINE.TXT


Richard Bonner
http://www.chebucto.ns.ca/~ak621/DOS/

Dr John Stockton

unread,
Aug 13, 2004, 6:07:00 AM8/13/04
to
JRS: In article <411a3a0e$0$3198$626a...@news.free.fr>, dated Wed, 11
Aug 2004 17:27:30, seen in news:alt.msdos.batch, Ralf Meuser
<rme...@free.fr> posted :

>I create a small batch file wich will merge some textfiles
>type %1 >> %2
>
>but some textfile don't end with a carriage return and the last line of one
>file will by append with the first line of the next file.
>
>How can I add an
>carriage return or a line feed ?

You do not, or should not, mean that. Text file newlines should all be
two characters, carriage-return line-feed.

If you pipe $1 through any HLL program that copies line-by-line, the
ends of lines, including the last will be normalised, but no lines
should be added.

Therefore, try

COLS <%1 1- >>$2

COLS via sig line 3 below. NOTE - maximum line-length 255 characters.
Check what happens if the file may contain control characters such as
FF, VT, BS.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk DOS 3.3, 6.20; Win98. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <URL:http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.

Phred

unread,
Aug 14, 2004, 10:32:36 AM8/14/04
to
In article <411a3a0e$0$3198$626a...@news.free.fr>, "Ralf Meuser" <rme...@free.fr> wrote:
>Hi there

G'day Ralf,

>I create a small batch file wich will merge some textfiles
>type %1 >> %2
>
>but some textfile don't end with a carriage return and the last line of one
>file will by append with the first line of the next file.
>
>How can I add an carriage return or a line feed ?

I have a small file (2 bytes) called ANSWER.NUL which contains only
the characters (in hex) 0D 0A (i.e. CR/LF) which I've used over the
years as a "response" where needed in batch files.

It can also be used by redirection to append the standard CR/LF pair
to files such as you describe.

Unfortunately, it is now 14 years old, and I'm damned if I can recall
how I made it! Quite possibly I used that old workhorse EDLIN, but
that seems to have disappeared from modern systems, so I couldn't try
it for you on this machine.

Given all that, this info is probably quite useless for your purpose.
But then, it may provoke someone to a more practical response!
(One has to be optimistic. ;-)


Cheers, Phred.

--
ppnerk...@THISyahoo.com.INVALID

foxidrive

unread,
Aug 14, 2004, 11:23:37 AM8/14/04
to
On Sat, 14 Aug 2004 14:32:36 GMT, Phred wrote:

> In article <411a3a0e$0$3198$626a...@news.free.fr>, "Ralf Meuser" <rme...@free.fr> wrote:
>>How can I add an carriage return or a line feed ?

> I have a small file (2 bytes) called ANSWER.NUL which contains only
> the characters (in hex) 0D 0A (i.e. CR/LF) which I've used over the
> years as a "response" where needed in batch files.
>
> It can also be used by redirection to append the standard CR/LF pair
> to files such as you describe.
>
> Unfortunately, it is now 14 years old, and I'm damned if I can recall
> how I made it!

With a batch file :)

echo.>ANSWER.NUL

Although 14 years ago the echo command couldn't echo a blank line/CRLF, if
my memory is not totally fscked up.

Dr John Stockton

unread,
Aug 14, 2004, 1:14:38 PM8/14/04
to
JRS: In article <2o6m3jF...@uni-berlin.de>, dated Sat, 14 Aug 2004
14:32:36, seen in news:alt.msdos.batch, Phred
<ppnerkDE...@yahoo.com> posted :

>
>I have a small file (2 bytes) called ANSWER.NUL which contains only
>the characters (in hex) 0D 0A (i.e. CR/LF) which I've used over the
>years as a "response" where needed in batch files.
>
>It can also be used by redirection to append the standard CR/LF pair
>to files such as you describe.
>
>Unfortunately, it is now 14 years old, and I'm damned if I can recall
>how I made it! Quite possibly I used that old workhorse EDLIN, but
>that seems to have disappeared from modern systems, so I couldn't try
>it for you on this machine.


echo.>answer.nul

should suffice; or use any plain text editor worthy of the name.

But to add CRLF only to those files that need it requires a means of
identifying them. Minitrue can be used, too, ISTM :-

mtr -x+ ? ([^\n])\Z = \1\r\n

so perhaps SED will do it?

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
I find MiniTrue useful for viewing/searching/altering files, at a DOS prompt;
free, DOS/Win/UNIX, <URL:http://www.idiotsdelight.net/minitrue/> Update hope?

Richard Bonner

unread,
Aug 14, 2004, 9:24:38 PM8/14/04
to
foxidrive wrote:

> echo.>ANSWER.NUL

> Although 14 years ago the echo command couldn't echo a blank line/CRLF,

*** It has been able to use "ECHO." since at least MS-DOS 5, released
in 1991. However, I vaguely remember seeing a technique for issuing a
blank line before that, but can't remember the syntax.

That aside, at that time, one could have used a blank-line file to
insert a blank line, as has already been suggested here.

Richard Bonner
http://www.chebucto.ns.ca/~ak621/DOS/

Phred

unread,
Aug 15, 2004, 11:09:30 AM8/15/04
to
In article <4q4bziowjjsc.q...@40tude.net>, foxidrive

Yeah. Your method certainly works. However, my old file is actually
dated 1 Dec 1990 (just after afternoon smoko by the time stamp :) but
I guess that's not *quite* 14 years ago. ;-)

Following up on Stocko's comment about text editors, I tried both
Notepad and EDIT under Win ME and, indeed, both were happy to create a
2-byte file of only CR/LF but the way to do it was subtlely different:

Notepad: Enter a blank line and Save As

EDIT: Simply open a new file by invoking EDIT and immediately Save As
(If you do as in Notepad, you get 4 bytes -- CR/LF/CR/LF)

Cheers, Phred.

--
ppnerk...@THISyahoo.com.INVALID

Dr John Stockton

unread,
Aug 15, 2004, 8:06:18 AM8/15/04
to
JRS: In article <4q4bziowjjsc.q...@40tude.net>, dated Sun,
15 Aug 2004 01:23:37, seen in news:alt.msdos.batch, foxidrive <foxidrive
@Shotmail.com.invalid> posted :

>
>Although 14 years ago the echo command couldn't echo a blank line/CRLF, if
>my memory is not totally fscked up.

A copy of Amstrad DOS 3.3, with command.com dated 1987-07-24, executing
echo.>a:x , has just generated a file containing exactly two characters,
OD OA .

--

nospam...@ualberta.ca

unread,
Aug 16, 2004, 4:02:41 PM8/16/04
to
Back to the original question of ADDING a carriage return to a txt file
(which may not have been the correct question):

echo.>>file.txt

of course, this actually adds a CR+LF under DOS, not just a CR.

In the original post,

type %1 >> %2

could perhaps have been replaced with copy %1+%2 %2
(depending on what version of DOS it is, this may not work, as it may not
allow overwriting one of the sources - the destination would have to be a
third file)
then, the "answer file" thing could be incorporated as something like
copy %1+answer.nul+%2

In article <2o9ckjF...@uni-berlin.de>, ppnerkDE...@yahoo.com (Phred)
wrote:

AnyBody43

unread,
Aug 19, 2004, 9:18:29 AM8/19/04
to
Dr John Stockton <sp...@merlyn.demon.co.uk> wrote in message news:<Lsz+n2D6...@merlyn.demon.co.uk>...

> JRS: In article <4q4bziowjjsc.q...@40tude.net>, dated Sun,
> 15 Aug 2004 01:23:37, seen in news:alt.msdos.batch, foxidrive <foxidrive
> @Shotmail.com.invalid> posted :
> >
> >Although 14 years ago the echo command couldn't echo a blank line/CRLF, if
> >my memory is not totally fscked up.
>
> A copy of Amstrad DOS 3.3, with command.com dated 1987-07-24, executing
> echo.>a:x , has just generated a file containing exactly two characters,
> OD OA .


As I have recently posted:-

Debug can be used to create files with ANY contents up to
about 64k in length.

Steps-
Create a file < 64k long.
e.g. echo fred > file.txt

now debug the file

debug file.txt

You can then view the file with the d command (dump?).
the file is loaded into memory at address 100 (HEX)
The q command quits from debug.
Change the length of the file with the rcx command and enter
the desired length in HEX.
Edit bytes with the e command {space} to leave unchanged
{enter} to finish editing
Write with w which writes cx register's worth of data.

You can get the debug commands from a file (or pipe?)
debug fred.txt < d-file
Extensive example of this posted to this group today.

I suspect debug is limited to 8.3 filemanes.


H:\temp>echo fred > file.txt

H:\temp>dir file.txt
19/08/2004 13:51 7 file.txt
H:\temp>

H:\temp>debug file.txt
-d
0C6F:0100 66 72 65 64 20 0D 0A D0-C0 24 01 D0 E4 0A C4 C3 fred ....$......
0C6F:0110 1E E8 E4 FF 8E 1E FE 95-A2 14 06 80 34 00 5E 0C ............4.^.
<snipped>
-rcx
CX 0007
:2
-e 100
0C6F:0100 66.0d 72.0a # only 0d{space}0a typed
-w
Writing 00002 bytes
-q

H:\temp>dir file.txt
19/08/2004 14:10 2 file.txt
H:\temp>

AnyBody43

unread,
Aug 19, 2004, 9:18:39 AM8/19/04
to
Dr John Stockton <sp...@merlyn.demon.co.uk> wrote in message news:<Lsz+n2D6...@merlyn.demon.co.uk>...
> JRS: In article <4q4bziowjjsc.q...@40tude.net>, dated Sun,
> 15 Aug 2004 01:23:37, seen in news:alt.msdos.batch, foxidrive <foxidrive
> @Shotmail.com.invalid> posted :
> >
> >Although 14 years ago the echo command couldn't echo a blank line/CRLF, if
> >my memory is not totally fscked up.
>
> A copy of Amstrad DOS 3.3, with command.com dated 1987-07-24, executing
> echo.>a:x , has just generated a file containing exactly two characters,
> OD OA .

James Pryor

unread,
Aug 19, 2004, 5:06:58 PM8/19/04
to
AnyBody43 wrote:

___________________________________________________________
If you think debug is limited to 64K bytes, add these lines and continue.

-rbx
BX 0000
:ff

But you better have 16,711,680 more bytes of disk space available.

I don't recall the results if you don't have 16M memory available.
___________________________________________________________

Todd Vargo

unread,
Aug 19, 2004, 4:47:57 PM8/19/04
to

"AnyBody43" <anyb...@hotmail.com> wrote in message
news:3adc58e4.04081...@posting.google.com...

> Debug can be used to create files with ANY contents up to
> about 64k in length.

Up to? No, debug can create files much larger than 64KB.

--
Todd Vargo (remove hyphen to reply by email)


AnyBody43

unread,
Aug 20, 2004, 9:06:39 AM8/20/04
to
James Pryor <jpr...@wi.rr.com> wrote
> AnyBody43 wrote:
> >
> > Debug can be used to create files with ANY contents up to
> > about 64k in length.
> >
> If you think debug is limited to 64K bytes, add these lines and continue.
>
> -rbx
> BX 0000
> :ff
>
> But you better have 16,711,680 more bytes of disk space available.
>
> I don't recall the results if you don't have 16M memory available.
> ___________________________________________________________

Thanks, I didn't know that the length written was bx:cx.
That is (bx << 8 ) + cx.

The bigest files that I have ever written with debug were .com
files and as you will know (or will be correcting me shortly)
they are limited to 64k (less PSP?).

Mike Jones

unread,
Aug 20, 2004, 2:25:23 PM8/20/04
to
Todd Vargo wrote:
> "AnyBody43" <anyb...@hotmail.com> wrote in message
> news:3adc58e4.04081...@posting.google.com...
>
>> Debug can be used to create files with ANY contents up to
>> about 64k in length.
>
> Up to? No, debug can create files much larger than 64KB.
why not give the info?
- set bx:cx to filesize

a bit more work needed to fill with data though


James Pryor

unread,
Aug 20, 2004, 2:38:08 PM8/20/04
to
AnyBody43 wrote:

Have you ever patched a large .EXE file? I have, but only under duress!

It's almost as much fun as using a disk sector editor to apply a patch.

Floppy disk editing and recovery was the reason why I became interested
in using debug for other purposes than quick and dirty programming.

_______________
@goto run
'AMBR.bat
'put a disk in drive A:

l100 0 0 1
d100 l200
q
q

:run
debug<AMBR.bat
_______________

Shows you the contents of the first sector of a floppy in A:.
Use a 50 line screen to see all of it, or output to a file.

If you want to save a copy, add a name, cx=200, and write before the q's.

Todd Vargo

unread,
Aug 20, 2004, 4:08:44 PM8/20/04
to
"Mike Jones" <DMike...@hotmail.com> wrote in message
news:2omu0lF...@uni-berlin.de...

> Todd Vargo wrote:
> > "AnyBody43" <anyb...@hotmail.com> wrote in message
> > news:3adc58e4.04081...@posting.google.com...
> >
> >> Debug can be used to create files with ANY contents up to
> >> about 64k in length.
> >
> > Up to? No, debug can create files much larger than 64KB.
> why not give the info?

Sorry, I was not aware this is now alt.msdos.debug :-/

Besides, as I expected, someone did shortly after I posted.

0 new messages