我試圖從history
命令的輸出中使用命令只輸出第二個字 grep。到目前爲止,我有正則表達式:從bash歷史記錄中獲取第二個字
[^\d\s](\w+)
相同的輸入:
10004 history --help 10005 history -h 10006 man history 10007 history 10008 sort history | uniq -c 10009 history | sort | uniq -c 10010 history | sort 10011 PATH 10012 compgen -c 10013 compgroups 10014 compgroups -a 10015 whence -pm '*' 10016 history | grep -Eo '^[^ ]+'
它選擇號碼之後的一切,但也都在第二個字(在這種情況下,命令)之後。
我該如何對此進行微調?
謝謝!你的選擇數字以及我否定的數字,我有:'[^ \ d + \ s +]([^ \ s] +)'但是regex似乎比regexpal.com中的第二個單詞多。我在這裏錯過了什麼? –
每個正則表達式引擎都不同,儘管這不應該發生。 –
和您的正則表達式演示只顯示第一行中第二個字的選擇。剩餘的輸入沒有匹配。那不是我期待的 –