[問題] grep 擷取任意字元的問題

看板Linux作者 (宅男一枚)時間7年前 (2018/09/07 23:20), 編輯推噓3(304)
留言7則, 3人參與, 7年前最新討論串1/1
不好意思 這問題 我找很久了 還是找不到 問題是這樣 假如我有一個文字檔 例如: I wanna leave my footprints on the sands of time Know there was something that, and something that I left behind When I leave this world, I'll leave no regrets Leave something to remember, 我想找這行出來 there was something that, and something that I left behind 我下的方式是 cat txt | grep -o "there * that" 這邊* 我想要說可以是任意字串 但grep 任意字元 似乎不是用* 我google很久 有找到一個 \w* 可以表示任意一個字元 但這不符合我的需求 因為我不知道中間的任意字元會有幾個 請問有人有好方法嗎?? 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 59.126.145.236 ※ 文章網址: https://www.ptt.cc/bbs/Linux/M.1536333652.A.560.html

09/07 23:32, 7年前 , 1F
* 代表跟前一個字元一樣, 0~N 個
09/07 23:32, 1F

09/07 23:33, 7年前 , 2F
cat txt |grep "there .* that"
09/07 23:33, 2F

09/07 23:35, 7年前 , 3F
然後加 -o 只會從 there 顯示到 that (only-matching)
09/07 23:35, 3F

09/07 23:35, 7年前 , 4F
可以參考一下 regular expression
09/07 23:35, 4F

09/08 01:52, 7年前 , 5F
regexp 正則表示式和 glob 萬用字元是二種不同的東西,
09/08 01:52, 5F

09/08 01:52, 7年前 , 6F
grep 只支援 regexp 。
09/08 01:52, 6F

09/11 16:33, 7年前 , 7F
參考 「正規表示法」
09/11 16:33, 7F
文章代碼(AID): #1RafTKLW (Linux)
文章代碼(AID): #1RafTKLW (Linux)