Windows 上有 cat 的替代品吗
-
09-06-2019 - |
题
我需要用一个连接两个二进制文件 *.bat
Windows 上的脚本。
我怎样才能做到这一点?
解决方案
视窗 type
命令的工作方式与 UNIX 类似 cat
.
示例1:
type file1 file2 > file3
相当于:
cat file1 file2 > file3
示例2:
type *.vcf > all_in_one.vcf
此命令会将所有 vcard 合并为一个。
其他提示
您可以使用 copy /b
像这样:
copy /b file1+file2 destfile
如果您可以控制正在工作的机器,我强烈建议安装 GnuWin32. 。只需“下载全部”并让 wget 程序检索所有包。然后,您将可以访问 cat、grep、find、gzip、tar、less 以及数百个其他工具。
GnuWin32 是我在新的 Windows 机器上首先安装的东西之一。
无耻的 PowerShell 插件(因为我认为学习曲线很痛苦,所以在任何机会教授一些东西会有所帮助)
Get-Content file1,file2
注意 type
是 Get-Content 的别名,所以如果你更喜欢它,你可以写:
type file1,file2
只需使用 dos copy 命令来复制多个源文件和一个目标文件。
复制文件1+文件2附加文件
您可能需要二进制文件的 /B 选项
在Windows 10的Redstone 1版本中,Windows为NTOS内核添加了真正的Linux子系统。我认为最初它是为了支持 Android 应用程序,也许还有 docker 类型的场景。Microsoft 与 Canonical 合作并添加了实际的本机 bash shell。此外,您还可以使用 apt 包管理器来获取许多 Ubuntu 包。例如,您可以执行 apt-get gcc 来安装 GCC 工具链,就像在 Linux 机器上一样。
如果我在大学时存在这样的事情,我想我可以在本机 Windows bash shell 中完成大部分 Unix 编程作业。
如果您只想将文本附加到现有文件的末尾,可以使用 >> 管道。前任:
echo new text >>existingFile.txt
如果您必须使用批处理脚本并安装了 python,这里是 多角体 批处理和Python回答:
1>2# : ^
'''
@echo off
python "%~nx0" " %~nx1" "%~nx2" "%~nx3"
exit /b
rem ^
'''
import sys
import os
sys.argv = [argv.strip() for argv in sys.argv]
if len(sys.argv) != 4:
sys.exit(1)
_, file_one, file_two, out_file = sys.argv
for file_name in [file_one, file_two]:
if not os.path.isfile(file_name):
print "Can't find: {0}".format(file_name)
sys.exit(1)
if os.path.isfile(out_file):
print "Output file exists and will be overwritten"
with open(out_file, "wb") as out:
with open(file_one, "rb") as f1:
out.write(f1.read())
with open(file_two, "rb") as f2:
out.write(f2.read())
如果保存为 join.bat 用法将是:
join.bat file_one.bin file_two.bin out_file.bin
也谢谢你 这个答案 为了灵感。
我尝试重新加入 Linux 服务器中已分割的 tar 存档。
我发现如果我使用 type
在 Windows 中 cmd.exe
, ,这会导致文件以错误的顺序加入。(即 type
有时会先放 XXXX.ad 然后 XXXX.ac , XXXX.aa 等...)
于是,我找到了一个工具,名为 bat
在 GitHub 中 https://github.com/sharkdp/bat 它具有 Windows 版本,并且具有更好的代码突出显示,重要的是,它可以在 Windows 上正常工作以重新加入 tar 存档!
因此,我正在寻找具有abillity的类似解决方案来保留EOL字符,并且发现那里没有办法,所以我尽我所能,并制作了自己的Utillity,这是Windows的本地猫 - https://mega.nz/#!6AVgwQhL!qJ1sxx-tLtpBkPIUx__iQDGKAIfmb21GHLFerhNoaWk
Usage: cat file1 file2 file3 file4 -o output.txt
-o | Specifies the next arg is the output, we must use this rather than ">>" to preserve the line endings
我称其为 Sharp-cat,因为它是用 C# 构建的,请随时使用防病毒软件进行扫描,并且将根据要求提供源代码