Windows batch split long string by length 64

二次信任 提交于 2020-06-13 09:24:09

问题


I have tried to figure this out without any luck. Can anyone help on this?

I have a file: input.txt This file contains a long string - and i want to split the long string into 64 long string chunks, and save the content to a different file.

I don't have much so far, i know i have to use the for loop:

echo off
set /p base64=<input.txt

for /f "%base64:~0,64%" %%G IN %base64% DO echo %%G

But how to make the loop for each 64 characters in line - and in a batch script?

Any help will be appreciated.


回答1:


@ECHO OFF
SETLOCAL
(
FOR /f "delims=" %%i IN (input.txt) DO SET longline=%%i&call:breakit
)>output.txt
GOTO :eof

:breakit
ECHO %longline:~0,64%
SET longline=%longline:~64%
IF DEFINED longline GOTO breakit
GOTO :EOF 

This should do what you want - but it may depend on the content of the file as batch has sensitivities to certain characters.



来源:https://stackoverflow.com/questions/16319355/windows-batch-split-long-string-by-length-64

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!