Windows批处理长度为64的长字符串

时间:2023-01-14 21:40:14

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.

我有一个文件:input.txt这个文件包含一个长字符串 - 我想将长字符串拆分为64个长字符串块,并将内容保存到另一个文件。

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

到目前为止我没有太多,我知道我必须使用for循环:

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?

但是如何在每个64个字符的循环中和批处理脚本中制作循环?

Any help will be appreciated.

任何帮助将不胜感激。

1 个解决方案

#1


2  

@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.

这应该做你想要的 - 但它可能取决于文件的内容,因为批处理对某些字符有敏感性。

#1


2  

@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.

这应该做你想要的 - 但它可能取决于文件的内容,因为批处理对某些字符有敏感性。