使用以下示例,我需要过滤掉仅包含'ABC'的行,同时跳过与'ABC'匹配的包含方括号的行:
2012-04-04 04:13:48,760~sample1~ABC[TLE 5332.233 2/13/2032 3320392]:CAST 2012-04-04 04:13:48,761~sample2~ABC 2012-04-04 04:13:48,761~sample3~XYZ[BAC.CAD.ABC.CLONE 232511]:TEST
这是我所拥有的,但到目前为止,我无法成功过滤掉带方括号的行:
bash-3.00$ cat Metrics.log | grep -e '[^\[\]]' | grep -i 'ABC'
请帮帮忙?
答案 0 :(得分:3)
根据评论编辑:
尝试grep -i 'ABC' Metrics.log | grep -v "[[]" | grep -v "ABC\w"
输入:
2012-04-04 04:13:48,760~sample1~ABC[TLE 5332.233 2/13/2032 3320392]:CAST
2012-04-04 04:13:48,761~sample2~ABC
2012-04-04 04:13:48,761~sample3~XYZ[BAC.CAD.ABC.CLONE 232511]:TEST
2012-04-04 04:13:48,761~sample4~XYZ
2012-04-04 04:13:48,761~sample5~ABCD
2012-04-04 04:13:48,761~sample6~ABC:TEST
输出:
2012-04-04 04:13:48,761~sample2~ABC
2012-04-04 04:13:48,761~sample6~ABC:TEST
答案 1 :(得分:1)
$cat log | grep -v '\[.*\]' | grep ABC