我有此日志文件,并且我试图避免打印包含模式“ APLHA”的文本。
+++ skdfhahjsahsdjk >
** ALPHA EDFJDJFKLJDKFJKSDLFJL
SDFSDGDRGRTG
WEFETTFYRT #168113++-
+++ skdfhahjsahsdjk >
* KJENRFKES DFJKLSDFJEDFJDJFKLJDKFJKSDLFJL
SDFSDGDRGRTG
WEFETTFYRT #168113++-
+++ skdfhahjsahsdjk >
CL mesukww juwaehdiearfa
SDFSDGDRGRTG
WEFETTFYRT #168113++-
+++ skdfhahjsahsdjk >
*C KJENRFKESDFJ ksludhieokdaewmdp
SDFSDGDRGRTG
WEFETTFYRT #168113++-
+++ skdfhahjsahsdjk >
** BETA EDFJDJFKLJDKFJKSDLFJL
SDFSDGDRGRTG
WEFETTFYRT #168113++-
我尝试过这种方式,但没有成功。它会打印出除“ ALPHA”外的其余文本
cat日志文件| grep -v“ ALPHA”
结果:
+++ skdfhahjsahsdjk >
SDFSDGDRGRTG
WEFETTFYRT #168113++-
我期望未打印包含“ ALPHA”的整个日志,如下所示:
+++ skdfhahjsahsdjk >
* KJENRFKES DFJKLSDFJEDFJDJFKLJDKFJKSDLFJL
SDFSDGDRGRTG
WEFETTFYRT #168113++-
+++ skdfhahjsahsdjk >
CL mesukww juwaehdiearfa
SDFSDGDRGRTG
WEFETTFYRT #168113++-
+++ skdfhahjsahsdjk >
*C KJENRFKESDFJ ksludhieokdaewmdp
SDFSDGDRGRTG
WEFETTFYRT #168113++-
+++ skdfhahjsahsdjk >
** BETA EDFJDJFKLJDKFJKSDLFJL
SDFSDGDRGRTG
WEFETTFYRT #168113++-
对于这种情况,您能否提出其他解决方案的建议?
关于Dom
答案 0 :(得分:1)
尝试一下:
awk 'BEGIN{RS=ORS="\n\n"}!/ALPHA/' file
答案 1 :(得分:0)
使用perl
的slurp模式(启用-00
)的替代解决方案。这将告诉perl
认为段落是一个记录而不是行。以后很清楚,仅当ALPHA
不存在时才打印。
perl -00 -ne 'print if !/ALPHA/' inputfile
+++ skdfhahjsahsdjk >
* KJENRFKES DFJKLSDFJEDFJDJFKLJDKFJKSDLFJL
SDFSDGDRGRTG
WEFETTFYRT #168113++-
+++ skdfhahjsahsdjk >
CL mesukww juwaehdiearfa
SDFSDGDRGRTG
WEFETTFYRT #168113++-
+++ skdfhahjsahsdjk >
*C KJENRFKESDFJ ksludhieokdaewmdp
SDFSDGDRGRTG
WEFETTFYRT #168113++-
+++ skdfhahjsahsdjk >
** BETA EDFJDJFKLJDKFJKSDLFJL
SDFSDGDRGRTG
WEFETTFYRT #168113++-