如何在一个文件中找到行,而不是使用bash脚本查找其他文件?
发布时间:2020-12-15 19:06:26 所属栏目:安全 来源:网络整理
导读:想象文件1: #include "first.h"#include "second.h"#include "third.h"// more code here... 想象文件2: #include "fifth.h"#include "second.h"#include "eigth.h"// more code here... 我想得到文件2中包含的标题,但不包含在文件1中的标题,只有这些行
想象文件1:
#include "first.h" #include "second.h" #include "third.h" // more code here ... 想象文件2: #include "fifth.h" #include "second.h" #include "eigth.h" // more code here ... 我想得到文件2中包含的标题,但不包含在文件1中的标题,只有这些行。 #include "fifth.h" #include "eigth.h" 我知道如何在Perl / Python / Ruby中执行此操作,但是我想在不使用不同的编程语言的情况下完成此操作。
如果可以使用临时文件,请尝试:
grep include file1.h > /tmp/x && grep -f /tmp/x -v file2.h | grep include 这个 >从file1.h中提取所有文件,并将它们写入文件/ tmp / x 它可能不会正确地处理空白的差异等。 编辑: grep include file1.h > /tmp/x && grep -f /tmp/x -v file2.h | grep "^#include" (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |