我想从文件中抽取所有不包含特定模式的行。Bash - 从不包含特定模式的文件中获取行
pattern="tmp/[...]/include/linux/*.h"
file contains:
17937;/home/[...]/tmp/[...]/include/linux/header.h;484;16;[Other text here]
37417;/home/[...]/tmp/[...]/src/file.cpp;1851;41;[Other text here]
17945;/home/[...]/tmp/[...]/include/linux/*/header.h;484;16;[Other text here]
预期结果只是第二行。
我已经试过波纹线和我得到的文件的全部内容:
grep -E -v $pattern file
它只能与波纹管线,但它是不够的:
grep -E -v .h file
如何我可以获得所需的输出吗?
grep -E -v“tmp /\\[...\\]/include/linux/.*.h”将根据您的数据得到想要的结果。 – sigmalha
如果确定排除的行的模式是固定的,或者就像使用通配符,那么我不清楚:* .h - >排除扩展名为.h的所有文件。 – MarcM
这就像使用通配符。所有具有该模式的行被排除(所有.h行与相同的位置) –