2012-12-28 103 views
-1

grep "^\[bugID[[:digit:]]\{1,\}\]"是第一行。我怎样才能grepbugIDTICKET-grep搜索替换

[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

please,rephrase你的问题,并使用4个空格来缩进代码;你的文章很难编辑 – Rubens

+0

正如@rubens所说,请改述并提出一个问题 – simonmorley

回答

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] 
+0

感谢egrep解决方案的工作原理 – Vivek