过滤复杂文件中的特定模式
Filter specifik patern in a complex file
我有这个日志文件,我试图避免打印包含模式“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++-
我尝试通过这种方式但没有 successful.It 打印其余文本,"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
试一试:
awk 'BEGIN{RS=ORS="\n\n"}!/ALPHA/' file
使用 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++-
我有这个日志文件,我试图避免打印包含模式“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++-
我尝试通过这种方式但没有 successful.It 打印其余文本,"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
试一试:
awk 'BEGIN{RS=ORS="\n\n"}!/ALPHA/' file
使用 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++-