根据关键字将一个文件拆分为多个

时间:2016-01-08 09:39:39

标签: batch-file cmd

我希望在文件中包含特定关键字时将我的单个文件拆分为两个文件。请考虑我将整个内容放在一行中。因此,无法计算行号,然后将其拆分。

提前感谢您的帮助

1 个答案:

答案 0 :(得分:1)

@echo off
setlocal

rem Read the line from the file
for /F "delims=" %%a in (input.txt) do set "line=%%a"

rem Split the line at "from here " string
set "part1=%line:from here =from here" & set "part2=%"

rem Create the two output files
> output1.txt echo %part1%
> output2.txt echo %part2%

input.txt中:

This is my file content and I want to split file from here Content should be split to other file

output1.txt:

This is my file content and I want to split file from here

output2.txt:

Content should be split to other file

此方法最多只能从输入文件中读取8191个字符;如果输入文件包含特殊的批处理字符,它也会失败。

如果您想要更准确的答案,请发布更准确的问题......