grep搜索交替

时间:2012-12-28 12:06:33

标签: linux unix search grep

grep "^\[bugID[[:digit:]]\{1,\}\]"是第一行。我如何grep bugID TICKET-

[bugID12345] fix for performance issue

[TICKET-12345] fix for memory leak issue

[bugID23244] fix for performance issue

[TICKET-54678] fix for memory leak issue

1 个答案:

答案 0 :(得分:1)

egrep支持与|进行轮换,[还需要转义:

egrep "^\[(bugID|TICKET-)[[:digit:]]{1,}\]" file
[bugID12345] fix for performance issue
[TICKET-12345] fix for memory leak issue
[bugID23244] fix for performance issue
[TICKET-54678] fix for memory leak issue

如果您不想要整行,请使用-o选项:

egrep -o "^\[(bugID|TICKET-)[[:digit:]]{1,}\]" file
[bugID12345]
[TICKET-12345]
[bugID23244]
[TICKET-54678]