【发布时间】:2015-12-30 00:34:28
【问题描述】:
我正在尝试通过regex 发送grep,但我无法弄清楚我的正则表达式有什么问题。我找不到任何 bash 正则表达式测试人员,所以这真的很难弄清楚。
这是我的正则表达式
[0-9]*\.[0-9]*[G][:space:]*\.\/[bbg-sevent-test-][0-9]*
我正在尝试将我的正则表达式与这段文字相匹配
2.0G ./bbg-sevent-test-132^M
我正在运行的命令是:
./kafka_prefill.sh | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" | grep '[0-9]*\.[0-9]*[G][:space:]*\.\/[bbg-sevent-test-][0-9]*' > data3.txt
它的作用是运行我的脚本,翻译/删除部分输出,然后基于正则表达式 grep 并将其放入文件 data3.txt
我目前收到此错误:
grep: Invalid range end
** 更新**感谢 Ed Plunkett
更新的正则表达式:
^[0-9]*\.[0-9]*[G][[:space:]]*\.\/bbg-sevent-test-[0-9]*$
我的命令不再有正则表达式错误。然而,没有什么是匹配的。这是一个示例输出:
********************************************************************************^M
This is a private computer system containing information that is proprietary^M
and confidential to the owner of the system. Only individuals or entities^M
authorized by the owner of the system are allowed to access or use the system.^M
Any unauthorized access or use of the system or information is strictly^M
prohibited.^M
^M
All violators will be prosecuted to the fullest extent permitted by law.^M
********************************************************************************^M
Last login: Tue Dec 29 16:43:23 2015 from 10.81.64.204^M^M
sudo bash^M
cd /data/kafka/tmp/kafka-logs/^M
du -kh . | egrep "bbg-sevent-test-*"^M
-bash: ulimit: open files: cannot modify limit: Operation not permitted^M
### Trinity env = prod ###^M
### Kafka Broker Id = 1 ###^M
### Kafka Broker must be started as root!! ###^M
exit^M
exit^M
### Trinity env = prod ###^M
### Kafka Broker Id = 1 ###^M
### Kafka Broker must be started as root!! ###^M
^[]0;root@ip-10-81-66-20:/home/ec2-user^G^[[?1034h[root@ip-10-81-66-20 ec2-user]# cd /data/kafka/tmp/kafka-logs/^M
^[]0;root@ip-10-81-66-20:/data/kafka/tmp/kafka-logs^G[root@ip-10-81-66-20 kafka-logs]# du -kh . | egrep "bbg-sevent-test-*"^M
2.2G ./bbg-sevent-test-439^M
2.2G ./bbg-sevent-test-638^M
2.2G ./bbg-sevent-test-679^M
2.2G ./bbg-sevent-test-159^M
我只是想匹配这个位
2.2G ./bbg-sevent-test-159
【问题讨论】:
-
你的
[:space:]只匹配文字字符:space,你需要[[:space:]]。下面的 Ed 也表明了这一点。祝大家好运。