Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.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
使用Unix以外的命令在Unix中附加两个或多个txt/html文件_Unix - Fatal编程技术网

使用Unix以外的命令在Unix中附加两个或多个txt/html文件

使用Unix以外的命令在Unix中附加两个或多个txt/html文件,unix,Unix,如何在Unix中将两个或多个txt/html文件附加到单个文件。我知道cat命令在此上下文中的用法,但我无法在代码中使用它。除了在UNIX中使用cat命令之外,还有其他选择吗?是。负载 Python: import sys for filename in sys.argv[1:]: with open(filename) as f: print(f.read(), end = '') 狂欢节: Node.js: var fs = require("fs"); for (

如何在Unix中将两个或多个txt/html文件附加到单个文件。我知道cat命令在此上下文中的用法,但我无法在代码中使用它。除了在UNIX中使用cat命令之外,还有其他选择吗?

是。负载

Python:

import sys
for filename in sys.argv[1:]:
    with open(filename) as f:
        print(f.read(), end = '')
狂欢节:

Node.js:

var fs = require("fs");
for (var i = 2; i < process.argv.length; i += 1) {
    process.stdout.write(fs.readFileSync(process.argv[i]));
}

如果您可以在编程语言中执行此操作,则可以实现您的功能。

您使用的是哪种编程语言?
array_shift($argv);
foreach ($argv as $filename) {
    echo file_get_contents($filename);
}
var fs = require("fs");
for (var i = 2; i < process.argv.length; i += 1) {
    process.stdout.write(fs.readFileSync(process.argv[i]));
}
for each filename:
    read filename's contents
    output what was just read