比较文件行以匹配第二个文件中的任何位置 [英] Compare file lines for match anywhere in second file

查看:74
本文介绍了比较文件行以匹配第二个文件中的任何位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这令人沮丧。
我有2个文本文件,每行只是一个电话号码。
我需要从file1中读取第一行,并在file2中搜索匹配项。
如果不匹配,则将行值写入输出文件。
我一直在尝试,但是我知道它是错的。

This is frustrating. I have 2 text file that are just a phone number per line. I need to read the first line from file1, and search file2 for a match. If there is a no match, write the line value to an output file. I've been trying this but I know its wrong.

$file1 = 'pokus1.txt';
$file2 = 'pokus2.txt';

open (F1, $file1) || die ("Could not open $file1!");
open (F2, $file2) || die ("Could not open $file2!");
open (OUTFILE, '>>output\output_x1.txt');
@f1data = <F1>;
@f2data = <F2>;

while (@f1data){
    @grp = grep {/$f1data/} @f2data;

    print OUTFILE "$grp";
}
close (F1);
close (F2);
close (OUTFILE);

我希望有人可以提供帮助吗?
谢谢
布伦特

I hope someone can help? Thanks Brent

推荐答案

bash:

grep -vf file1 file2> file3

grep -vf file1 file2 > file3

grep -f file1 file2> file4

grep -f file1 file2 > file4

这篇关于比较文件行以匹配第二个文件中的任何位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆