我发现每次使用
将所有文件连接到一个文件中copy *.txt all.txt
,文件末尾有一个Ctrl-Z字符。我不想要这个角色。有没有办法编写批处理脚本来删除此字符或避免这种情况发生?
我想做的是
cat *.txt > all.txt
在linux中。
答案 0 :(得分:3)
在CP / M天中,文件大小不是以字节记录,而是以128字节的BLOCKS记录。因此,有必要分配一个END-OF-FILE字节(^ Z = 1AH)来表示部分填充的文本文件块(并且no-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
请注意juxataposing /a
和/b
如何产生不同的结果,所有结果都包含^Z
- 包含甚至附加。
另请注意,如果源是BINARY文件并且省略COPY
开关,则简单/b
可能会失败。我从来没有调查过它,但我发现它偶尔会复制.MPG
。我怀疑如果^Z
在任何字节> = 80H之前出现在文件中,那么该文件被假定为ASCII并因此在那里毫不客气地终止 - 但正如我所说,我没有调查它。
答案 1 :(得分:2)
试试这个:
copy /b *.txt all.txt
如需帮助,请输入help copy
。