相关疑难解决方法(0)

比较两个文件的匹配行并存储阳性结果

我有两个文件。

文件 1:

A0001  C001
B0003  C896
A0024  C234
.
B1542  C231
.
upto 28412 such lines
Run Code Online (Sandbox Code Playgroud)

文件2:

A0001
A0024
B1542
.
.
and 12000 such lines.
Run Code Online (Sandbox Code Playgroud)

我想将文件 2 与文件 1 进行比较并存储文件 1 中的匹配行。我尝试过 Perl 和 Bash,但似乎都没有工作。

我最近尝试的事情是这样的:

for (@q) # after storing contents of second file in an array
{
        $line =`cat File1 | grep $_`; #directly calling File 1 from bash
        print $line;
}
Run Code Online (Sandbox Code Playgroud)

但它失败了。

bash files file-comparison

14
推荐指数
2
解决办法
6万
查看次数

标签 统计

bash ×1

file-comparison ×1

files ×1