Solved How to add CRLF after 128 characters using a batch file?

May 15, 2015 at 09:52:30
Specs: Windows 7
I receive a text file without any line breaks in it. I need to write a batch file that takes that filename as a parameter, reads the file, and adds carriage return and line feed characters after every 128 characters.

Can anyone help me with this?

See More: How to add CRLF after 128 characters using a batch file?

Report •

May 15, 2015 at 19:28:20
✔ Best Answer
:: begin batch script - output goes to "snrtest", input is from cmdline
@echo off>snrtest & setlocal enabledelayedexpansion
set x=
for /f "tokens=*" %%a in (%1) do set x=!x!%%a
>>snrtest echo %x:~0,128%
rem this was the original erronious posted line: set x=%:~129%
rem corrected line follows:
set x=%x:~129%
if "%x%" neq "" goto :10
:: end batch
edited to fix my fat-fingered typo. sorry.

message edited by nbrane

Report •

May 19, 2015 at 11:30:55
Thank you for your input, nbrane.

But unless I screwed it up, the output was simply the original file contents followed by :~129 in an endless loop, as follows:


message edited by Snilref64

Report •

May 19, 2015 at 20:34:35
Sorry, typo error, dropped one character from this line:
set x=%:~129%

should have been:
set x=%x:~129%

I fixed it in my original post as well, for clarity (NOT to hide my blunder, ha ha!)

Report •

Related Solutions

May 20, 2015 at 08:42:04
That works perfectly.

Thank you so much, nbrane.

Report •

Ask Question