- 论坛徽章:
- 18
|
大家好!
我有一个问题向大家请教。
在文本文件/etc/motd中有一串数字字符串,其结构是:
前面1个数字,中间一个减号,后面7个数字。
例如:
1-5702630
整个文本如下:- Oracle Corporation SunOS 5.10 Generic Patch January 2005
- Customer DB restored for AR 1-5702630:
- Traps for hardware Anomoly errors (pchip memory, xplerror etc) from TiMOS8.0 to SAM10.0 are not resulting in alarms.
复制代码 我想从文本中找到这个数字,应该怎么办呢?
我对正则表达式还是不太熟悉,看了规则,但是怎么试都试不出来。- [root@dhp2:/]# grep '(\d)-(\d){7}' /etc/motd
- [root@dhp2:/]# grep "\\d+[-]+\\d{7}" /etc/motd
- [root@dhp2:/]# grep "\\d[-]\\d{7}" /etc/motd
- [root@dhp2:/]# grep "\\d-\\d{7}" /etc/motd
- [root@dhp2:/]# grep "(\\d-)\\d{7}" /etc/motd
- [root@dhp2:/]# grep "(\\d{1}-)\\d{7}" /etc/motd
- [root@dhp2:/]# grep "([1-9]{1}-)[0-9]{7}" /etc/motd
- [root@dhp2:/]# grep "([1-9]{1}-)[0-9]{7}" /etc/motd
- [root@dhp2:/]# grep "[1-9]{1}-[0-9]{7}" /etc/motd
- [root@dhp2:/]# grep "[1-9]{1}\-[0-9]{7}" /etc/motd
- [root@dhp2:/]# grep "[1-9]{1}+(\-[0-9]{7})" /etc/motd
复制代码 请各位高手指点一下。
谢谢了。 |
|