我想grep
由regex
但我很難找出我的正則表達式有什麼問題。我找不到任何bash正則表達式測試人員,所以這真的很難弄清楚。grep根據正則表達式不匹配任何東西
這裏是我的正則表達式
[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
**更新**感謝埃德賓吉
更新的正則表達式:
^[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;[email protected]:/home/ec2-user^G^[[?1034h[[email protected] ec2-user]# cd /data/kafka/tmp/kafka-logs/^M
^[]0;[email protected]:/data/kafka/tmp/kafka-logs^G[[email protected] 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:]]'。以及埃德下面的表示。祝你們好運。 – shellter