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
Batch file 不跳过批处理文件中的空行_Batch File - Fatal编程技术网

Batch file 不跳过批处理文件中的空行

Batch file 不跳过批处理文件中的空行,batch-file,Batch File,我试图复制一个没有第1行的文件。 但我似乎无法正确复制它的内容 我就是这样尝试的: for /f "tokens=* skip=1" %%i in (input.txt) do ( echo %%i >> "output.txt" ) 当myinput.txt具有以下内容时: test1 1. test item1 2. test item2 3. test item3 它给了我这个: 1. test item1 2. test item2 3. test

我试图复制一个没有第1行的文件。 但我似乎无法正确复制它的内容

我就是这样尝试的:

for /f "tokens=* skip=1" %%i in (input.txt) do (
    echo %%i >> "output.txt"
)
当myinput.txt具有以下内容时:

test1

1. test item1

2. test item2

3. test item3
它给了我这个:

1. test item1    
2. test item2
3. test item3
预期输出:

1. test item1

2. test item2

3. test item3

如何实现这一点?

使用
for/f
无法做到这一点,来自
for/?
的文档非常坚定:

跳过空行。

对于这样一个简单的需求,它可以通过Windows
more
程序来满足,该程序可以从任意行开始,并且如果文件被重定向(至少达到一定大小),它实际上不会分页。这意味着可以用单个命令替换整个脚本:

c:\users\paxdiablo> more +2 input.txt >output.txt
c:\users\paxdiablo> type output.txt
1. test item1

2. test item2

3. test item3
对于更复杂的任务,或者如果您的文件比
more
无需分页就能处理的文件大,您可能应该停止使用(坦率地说是脑死的)旧Windows工具,转而使用PowerShell

或者为自己准备一些适合Windows的文本处理工具,如
sed
awk
(请参见),之后您可以执行以下操作(对于您的情况,尽管脚本现在可能任意复杂):

@ECHO关闭
SETLOCAL
设置“sourcedir=U:\sourcedir”
设置“destdir=U:\destdir”
设置“filename1=%sourcedir%\q47067655.txt”
设置“outfile=%destdir%\outfile.txt”
(对于/f“tokens=1*skip=1delims=:”%a IN('findstr/n/r.*“%filename1%”)执行回显(%%b)>%outfile%1”

(对于/f“令牌=1*跳过=1个令牌=]”中的%%a('find/n/v“”“
more
命令也有错误。它将自动暂停并在第65534行等待用户输入。另一个错误是,
more
命令总是删除选项卡。默认情况下,每个选项卡都替换为8个空格,但可以使用它的
/T
选项更改空格数。”。
c:\users\paxdiablo> awk "NR>2{print}" input.txt >output.txt