开发者

Simple but elusive expression

开发者 https://www.devze.com 2023-02-15 03:23 出处:网络
I feel even shy of asking this here but it took already more time than it should. Say I have these four files:

I feel even shy of asking this here but it took already more time than it should.

Say I have these four files:

IPCDR_ARB06067956VPLUS_T_201103
IPCDR_ARB06067957VPLUS_T_201103
IPCDR_MOV_ARB060679开发者_运维百科59VPLUS_T_20110
MOV_CDRARB06067959VPLUS_T_201103

I want to grep for only those starting with IPCDR_MOV and MOV_CDR.

First thing off was:

ls -1 | grep "^IPCDR_MOV|^MOV_CDR"

but didn't work.

I've done plenty of dumb tests (which I wont bother you with) and nothing comes out. Can someone please put me out of my pain?

Thanks!


Add the -E switch for using extended regex.

$ ls -1 | grep -E "^IPCDR_MOV|^MOV_CDR"
IPCDR_MOV_ARB06067959VPLUS_T_20110
MOV_CDRARB06067959VPLUS_T_201103


Use egrep instead of grep. Otherwise it's a literal string instead of a pattern.

0

精彩评论

暂无评论...
验证码 换一张
取 消