将两个文件内容连接到一个文件中

时间:2013-10-15 10:18:33

标签: batch-file

我使用wmic从Process Explorer收集了一些文本文件file1.txt中的一些数据,如下所示:

wmic process where Caption='NOTEPAD.exe' get ProcessId,VirtualSize /Format:Texttable > file1.txt

FILE1.TXT:

ProcessId  VirtualSize  
5752       74649600     
3932       76843610
1357       90215638

在另一个文本文件file2.txt中,我有以下数据:

FILE2.TXT:

Notepad.exe.exe pid: 5752 windows
Notepad.exe.exe pid: 3932 linux
Notepad.exe.exe pid: 1357 macos

现在,流程ID在两个文件中都匹配,因此我可以使用批处理脚本生成具有以下内容的统一单个输出文件(在两个文件中匹配processId):

Output.txt的:

windows  74649600  
linux    76843610
macos    90215638 

1 个答案:

答案 0 :(得分:2)

这适用于纯文本文件,但有时Wmic是一种奇怪的野兽 它有时会在输出中添加额外的回车。

@echo off
(for /f "skip=1 tokens=1,2" %%a in (file1.txt) do (
for /f "tokens=5" %%c in ('find " %%a " ^< file2.txt ') do echo %%c %%b
))>file3.txt