如何在一个文件中找到行,而不是使用bash脚本查找其他文件?

想象文件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和文件2的差异会产生:

#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
>使用此文件获取file2.h中不包含在此列表中的所有行
> extract中包含的所有文件都包含在file2.h的其余部分中

它可能不会正确地处理空白的差异等。

编辑:
为了防止误报,对最后一个grep使用不同的模式(感谢jw013提到这一点):

grep include file1.h > /tmp/x && grep -f /tmp/x -v file2.h | grep "^#include"

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...