我有一个带有以下文字的文件
^ [[8mha:AAAAYB + LCAAAAAAAAP9b85aBtbiIQSmjNKU4P0 + vJLE4u1gvPjexLDVPzxdEuhYV5Rf55ZekOlc7RKnPKH7IxMBQUcQgBdWQnJ9XnJ + TqucMoUEKGSCAEaSwAACsNFCqYAAAAA == ^ [[0米[ERROR] ^ [[8mha:AAAAYB + LCAAAAAAAAP9b85aBtbiIQSmjNKU4P0 + vJLE4u1gvPjexLDVPzxdEuhYV5Rf55ZekOlc7RKnPKH7IxMBQUcQgBdWQnJ9XnJ + TqucMoUEKGSCAEaSwAACsNFCqYAAAAA == ^ [[0米[ERROR] /选择/应用程序/ ElectronicTransactionVOtoDOMapper.java:[1060,1]错误:文件的到达端而解析^ [[8mha:AAAAYB + LCAAAAAAAAP9b85aBtbiIQSmjNKU4P0 + vJLE4u1gvPjexLDVPzxdEuhYV5Rf55ZekOlc7RKnPKH7IxMBQUcQgBdWQnJ9XnJ + TqucMoUEKGSCAEaSwAACsNFCqYAAAAA == ^ [[0米[ERROR] - > [说明1] ^ [[8mha:AAAAYB + LCAAAAAAAAP9b85aBtbiIQSmjNKU4P0 + vJLE4u1gvPjexLDVPzxdEuhYV5Rf55ZekOlc7RKnPKH7IxMBQUcQgBdWQnJ9XnJ + TqucMoUEKGSCAEaSwAACsNFCqYAAAAA == ^ [[0米[ERROR] ^ [[8mha:AAAAYB + LCAAAAAAAAP9b85aBtbiIQSmjNKU4P0 + vJLE4u1gvPjexLDVPzxdEuhYV5Rf55ZekOlc7RKnPKH7IxMBQUcQgBdWQnJ9XnJ + TqucMoUEKGSCAEaSwAACsNFCqYAAAAA == ^ [[0米[ERROR]要看到完整的堆栈错误的痕迹,用-e开关重新运行Maven
从上面的日志中,我只需要提取以下内容:
[ERROR]
[ERROR] /opt/app/ElectronicTransactionVOtoDOMapper.java:[1060,1] error: reached end of file while parsing
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch
最终,我不应该在日志中获取垃圾值,而是需要一条明确的错误消息。
你能帮助我在shell中获得正确的命令吗?
答案 0 :(得分:1)
可能应该在这里使用sed而不是grep。
sed -n '/ERROR/s/.*\(\[ERROR\].*\)$/\1/p' log_10-29-2016_04_12
只获取包含单词'ERROR'的行,并从'[ERROR]'的左边开始删除所有内容并打印其余部分。
答案 1 :(得分:0)
awk -vRS='^' -F "] " '/ERROR/{print "[ERROR] "$2}' file
答案 2 :(得分:0)
尝试使用以下grep命令来实现输出 -
vipin@kali:~$ grep "\[ERROR\]" kk.txt |cut -c6-
[ERROR]
[ERROR] /opt/app/ElectronicTransactionVOtoDOMapper.java:[1060,1] error: reached end of file while parsing
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch
解释:
\[ and \]
用于转义,-c6-
在第6个字符后打印到行尾。