Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.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
CMD或Powershell命令组合(合并)两个不相等文件中的行_Powershell_Cmd - Fatal编程技术网

CMD或Powershell命令组合(合并)两个不相等文件中的行

CMD或Powershell命令组合(合并)两个不相等文件中的行,powershell,cmd,Powershell,Cmd,我是脚本编写的新手。让我举一个我想要实现的例子。 这两个文件如下所示: 文件1:(仅供参考:我不知道会出现多少这样的行!) 第一组 第2组 第3组 第4组 .. .. n组 文件2:(仅供参考:我不知道会出现多少这样的行!) 正文1 正文2 .. . 身体 所需输出:因为文件1中的行始终大于文件2中的行。我希望文件2行在用完时从一开始就重复它们自己,但是从第一次运行结束的地方开始第二次运行;循环,直到完成文件1中的所有行 第1组身体1 第2组主体2 第3组身体1 第4组身体2 .. .. 群n体

我是脚本编写的新手。让我举一个我想要实现的例子。 这两个文件如下所示:

文件1:(仅供参考:我不知道会出现多少这样的行!)

第一组
第2组
第3组
第4组
..
..
n组

文件2:(仅供参考:我不知道会出现多少这样的行!)

正文1
正文2
..
.
身体

所需输出:因为文件1中的行始终大于文件2中的行。我希望文件2行在用完时从一开始就重复它们自己,但是从第一次运行结束的地方开始第二次运行;循环,直到完成文件1中的所有行

第1组身体1
第2组主体2
第3组身体1
第4组身体2
..
..
群n体n

这是一项非常密集的任务,我有大约10000条这样的线路要合并。 请注意,行数始终是偶数对偶数的比率。 如果文件2中有10行,那么文件1中可能有100行(不是103等)


任何帮助都将不胜感激。

欢迎使用StackOverflow。请注意,StackOverflow不是代码工厂。到目前为止,您自己尝试过什么?$f1=获取内容文件1$f2=获取内容文件2($i=0;$i-lt$f1.Length;++$i){$f1[$i]+“`t”+$f2[$i]}我有这段代码,但它只在两个文件中的行数相等时起作用,我的文件与问题不符。另请参见:Thank you@iRon,它为10个条目的文件工作。我希望当我得到10000行的文件时,它会发挥它的魔力
$f2 = Get-Content .\file2.txt               # Load all lines of file 2 into memory
$i = 0                                      # Initiate an index for file 2
Get-Content .\file1.txt | Foreach-Object {  # Pipe each line of file 1 into the for each loop
    if ($i -ge $f2.Count) { $i = 0 }        # Reset the index if it exceeds the line count of file 2
    $_, $f2[$i] -Join ' '                   # Join the lines and drop the result in the pipeline
    $i++                                    # Increase the index
} | Set-Content .\output.txt                # Save each line in .\output.txt