批处理文件来复制每一行中的.txt文件,然后创建新的.txt文件的每一行 [英] Batch File To Copy Every Line In .txt File And Then Create New .txt File For Each Line

查看:633
本文介绍了批处理文件来复制每一行中的.txt文件,然后创建新的.txt文件的每一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经.txt文件包含297行,我想的是每一行复制到新的.txt文件,因此它将包含297文件,文件名类似这样line1.txt line2.txt line3.txt每个文件,它可以使用批处理?

I have .txt file contain 297 line, i want every line of that copied into new .txt file, so it will contain 297 file, for file name each file like this line1.txt line2.txt line3.txt, it possible using batch?

我在这里尝试<一个使用findrepl.bat和教学形式href=\"http://stackoverflow.com/questions/19935669/batch-to-copy-first-line-of-multiple-text-files/19944265#19944265\">batch要复制的多个文本文件的第一行但那剧本第一行只。

I have try using findrepl.bat and instruction form here batch to copy FIRST line of multiple text files but thats script for first line only.

推荐答案

FOR / F 是你想要的,与使用的SET / A 来增加数字的变量。由于CMD /批次真的只有一冲卡读卡器pretending是一个壳, source_file.txt 的内容可导致脚本打破。特别是,如果有任何特殊的shell字符(比如&LT;!>或安培),外壳会间preT的特殊字符,而不仅仅是它们回显到输出文件

FOR /F is what you want, with the use of SET /A to numerically increment a variable. Because CMD/batch is really only a punch card reader pretending to be a shell, the contents of source_file.txt can cause the script to break. In particular, if it has any special shell characters (like < > ! " or &), the shell will interpret those as special characters and not just echo them to the output file.

SETLOCAL ENABLEDELAYEDEXPANSION
SET LINENO=1
FOR /F "delims=" %%l IN (source_file.txt) DO (
    ECHO %%l>file!LINENO!.txt
    SET /A LINENO=LINENO+1
)

这篇关于批处理文件来复制每一行中的.txt文件,然后创建新的.txt文件的每一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆