Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 通过分隔符将文本文件拆分为2个文件_Windows_Batch File_Cmd - Fatal编程技术网

Windows 通过分隔符将文本文件拆分为2个文件

Windows 通过分隔符将文本文件拆分为2个文件,windows,batch-file,cmd,Windows,Batch File,Cmd,我正在寻找一个简单的批处理脚本,将我的文本文件拆分为两个文件。文本文件之间用分隔符分隔 ============================================================================ 文本文件如下所示: test test1 test2 test5 test test1 test2 test5 ========================================================================

我正在寻找一个简单的批处理脚本,将我的文本文件拆分为两个文件。文本文件之间用分隔符分隔

============================================================================
文本文件如下所示:

test
test1
test2
test5
test
test1
test2
test5
============================================================================
test
test1
test2
test5
test
test1   
试试这个:

@echo off&setlocal
set "file=file.txt"
for /f "delims=[]" %%i in ('^<"%file%" find /n "="') do set "split=%%i"
(for /f "tokens=1*delims=[]" %%i in ('^<"%file%" find /n /v ""') do if %%i lss %split% echo(%%j)>"%file%.new1"
<"%file%">"%file%.new2" more +%split%
type "%file%.new?"
@echo off&setlocal
设置“file=file.txt”
对于(“^中的/f“delims=[]”%%i,请尝试以下操作:

@echo off&setlocal
set "file=file.txt"
for /f "delims=[]" %%i in ('^<"%file%" find /n "="') do set "split=%%i"
(for /f "tokens=1*delims=[]" %%i in ('^<"%file%" find /n /v ""') do if %%i lss %split% echo(%%j)>"%file%.new1"
<"%file%">"%file%.new2" more +%split%
type "%file%.new?"
@echo off&setlocal
设置“file=file.txt”

对于“^i”中的/f“delims=[]”%%i,我尝试运行此批处理文件,但在执行时,它挂起。我必须在要停止执行时终止它。这是一个“错误”在
findstr
中,您的输入文件必须在最后一行以
CR/LF
结尾。我进行了编辑,代码现在使用
find
,我希望这对您有用。如果我想按单词而不是整行分割文件,该怎么办?我尝试运行此批处理文件,但在执行时,它会挂起。当我想停止文件时,我必须终止它正在执行。这是一个“错误”在
findstr
中,您的输入文件必须在最后一行以
CR/LF
结尾。我进行了编辑,代码现在使用
find
,我希望这对您有用。如果我想按单词而不是整行分割文件,该怎么办?谢谢您的回复。当我运行此文件时,我不会得到任何输出。您应该更改
(myfile.txt)
使用您的文件路径…我对脚本做了一点更改,使其更易于使用谢谢您的回复。当我运行此文件时,我没有得到任何输出。您应该更改
(myfile.txt)
使用您的文件路径…我对脚本做了一点更改,使其更易于使用 file.txt.new1 test test1 test2 test5 test test1 test2 test5 file.txt.new2 test test1 test2 test5 test test1