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
Linux 如何使用dos批处理删除文件中的Ctrl-Z_Linux_Batch File_Copy_Dos_Cat - Fatal编程技术网

Linux 如何使用dos批处理删除文件中的Ctrl-Z

Linux 如何使用dos批处理删除文件中的Ctrl-Z,linux,batch-file,copy,dos,cat,Linux,Batch File,Copy,Dos,Cat,我发现每次我将所有文件连接到一个文件时 copy *.txt all.txt ,文件末尾有一个Ctrl-Z字符。我不想要这个角色。有没有办法编写一个批处理脚本来删除这个字符或避免这种情况发生 我想做的是 cat *.txt > all.txt 在linux中。尝试以下操作: copy /b *.txt all.txt 要获得帮助,请输入help copy在CP/M天数内,文件大小不是以字节为单位记录的,而是以128字节为单位的块。因此,有必要指定一个文件结束字节(^Z=1AH)来表

我发现每次我将所有文件连接到一个文件时

copy *.txt all.txt
,文件末尾有一个Ctrl-Z字符。我不想要这个角色。有没有办法编写一个批处理脚本来删除这个字符或避免这种情况发生

我想做的是

cat *.txt > all.txt 
在linux中。

尝试以下操作:

copy /b *.txt all.txt

要获得帮助,请输入
help copy

在CP/M天数内,文件大小不是以字节为单位记录的,而是以128字节为单位的块。因此,有必要指定一个文件结束字节(^Z=1AH)来表示部分填充的文本文件块(没有EOF表示“完全填充最后的128字节块”)

MSDOS及其衍生产品遵守了这一约定,这就是为什么
COPY CON:filename
以^Z终止的原因

COPY
命令允许对
^Z
进行不同的解释,因此可以使用
/a
/b
模式,如下代码所示:

@ECHO OFF
SETLOCAL
:: set COPYCMD=Y to auto-allow overwriting of destination
SET copycmd=Y
:: copy using FRED1.txt (no ^Z-terminal)
>NUL COPY /a fred1.txt freda1.txt
>NUL COPY fred1.txt fred1a.txt /a
>NUL COPY /b fred1.txt fredb1.txt
>NUL COPY fred1.txt fred1b.txt /b
>NUL COPY /a fred1.txt freda1a.txt /a
>NUL COPY /a fred1.txt freda1b.txt /b
>NUL COPY /b fred1.txt fredb1a.txt /a
>NUL COPY /b fred1.txt fredb1b.txt /b

DIR fred*1*|FIND /i "fred"
ECHO.

:: copy using FRED2.txt (has ^Z-terminal) to fred*2*
>NUL COPY /a fred1.txt fred2.txt
>NUL COPY /a fred2.txt freda2.txt
>NUL COPY fred2.txt fred2a.txt /a
>NUL COPY /b fred2.txt fredb2.txt
>NUL COPY fred2.txt fred2b.txt /b
>NUL COPY /a fred2.txt freda2a.txt /a
>NUL COPY /a fred2.txt freda2b.txt /b
>NUL COPY /b fred2.txt fredb2a.txt /a
>NUL COPY /b fred2.txt fredb2b.txt /b

DIR fred*2*|FIND /i "fred"
ECHO.

:: append-copy using FRED1.txt+FRED2.txt to fred*3*
>NUL COPY /a fred1.txt+fred2.txt freda3.txt
>NUL COPY fred1.txt+fred2.txt fred3a.txt /a
>NUL COPY /b fred1.txt+fred2.txt fredb3.txt
>NUL COPY fred1.txt+fred2.txt fred3b.txt /b
>NUL COPY /a fred1.txt+fred2.txt freda3a.txt /a
>NUL COPY /a fred1.txt+fred2.txt freda3b.txt /b
>NUL COPY /b fred1.txt+fred2.txt fredb3a.txt /a
>NUL COPY /b fred1.txt+fred2.txt fredb3b.txt /b

DIR fred*3*|FIND /i "fred"
ECHO.

:: append-copy using FRED2.txt+FRED2.txt to fred*4*
>NUL COPY /a fred2.txt+fred2.txt freda4.txt
>NUL COPY fred2.txt+fred2.txt fred4a.txt /a
>NUL COPY /b fred2.txt+fred2.txt fredb4.txt
>NUL COPY fred2.txt+fred2.txt fred4b.txt /b
>NUL COPY /a fred2.txt+fred2.txt freda4a.txt /a
>NUL COPY /a fred2.txt+fred2.txt freda4b.txt /b
>NUL COPY /b fred2.txt+fred2.txt fredb4a.txt /a
>NUL COPY /b fred2.txt+fred2.txt fredb4b.txt /b

DIR fred*4*|FIND /i "fred"
ECHO.

GOTO :EOF
运行结果:

26/07/2013  08:51                 7 fred1.txt
26/07/2013  08:51                 7 fred1a.txt
26/07/2013  08:51                 7 fred1b.txt
26/07/2013  08:51                 8 freda1.txt
26/07/2013  08:51                 8 freda1a.txt
26/07/2013  08:51                 7 freda1b.txt
26/07/2013  08:51                 7 fredb1.txt
26/07/2013  08:51                 7 fredb1a.txt
26/07/2013  08:51                 7 fredb1b.txt

26/07/2013  08:51                 8 fred2.txt
26/07/2013  08:51                 8 fred2a.txt
26/07/2013  08:51                 8 fred2b.txt
26/07/2013  08:51                 8 freda2.txt
26/07/2013  08:51                 8 freda2a.txt
26/07/2013  08:51                 7 freda2b.txt
26/07/2013  08:51                 8 fredb2.txt
26/07/2013  08:51                 8 fredb2a.txt
26/07/2013  08:51                 8 fredb2b.txt

26/07/2013  09:35                15 fred3a.txt
26/07/2013  09:35                14 fred3b.txt
26/07/2013  09:35                15 freda3.txt
26/07/2013  09:35                15 freda3a.txt
26/07/2013  09:35                14 freda3b.txt
26/07/2013  09:35                15 fredb3.txt
26/07/2013  09:35                16 fredb3a.txt
26/07/2013  09:35                15 fredb3b.txt

26/07/2013  09:35                15 fred4a.txt
26/07/2013  09:35                14 fred4b.txt
26/07/2013  09:35                15 freda4.txt
26/07/2013  09:35                15 freda4a.txt
26/07/2013  09:35                14 freda4b.txt
26/07/2013  09:35                16 fredb4.txt
26/07/2013  09:35                17 fredb4a.txt
26/07/2013  09:35                16 fredb4b.txt
请注意,将
/a
/b
并置会产生不同的结果,所有这些结果都包含了
^Z
的各种组合,甚至是附加的


还请注意,如果源文件是二进制文件且省略了
/b
开关,则简单的
复制可能会失败。我从未调查过它,但我发现它偶尔会在复制
.MPG
s时发生。我怀疑,如果
^Z
在任何字节>=80H之前出现在文件中,则该文件被假定为ASCII,因此在此处随意终止,但正如我所说,我没有对其进行调查。

您的意思是/B可以避免该字符?我看了手册,上面说/B表示二进制文件。这是什么意思?为什么它可以避免这个问题?对不起,我不知道为什么,但它是有效的。我猜,文本文件也是二进制文件。二进制复制是指
1:1
copy,no
EOF
appending.the/b仅将一个文件标记为二进制文件,因此“copy/b*.txt all.txt”是指将*.txt作为二进制文件打开,然后作为非二进制文件放入all.txt中。要使目标也是二进制的,您可以键入“copy/b*.txt/b all.txt”。Marcus,二进制表示控制字符。Ascii文件将删除所有不可打印的字符。