使用 sed 如何列印最后一個單詞中包含字母 a 的檔案中的所有行?
我嘗試過這樣的事情sed -n -E '/[ e]./w\./p' < 'textfile'
但我對 sed 很陌生,所以不太了解它。
uj5u.com熱心網友回復:
你可能會使用
sed -nE '/a[^[:space:]]*[[:space:]]*$/p' textfile
這里:
-n禁用行的默認列印-E擴展正則運算式/p列印尋址行
模式匹配:
a匹配a字符[^[:space:]]*匹配可選的非空白字符[[:space:]]*匹配可選空格$字串結束
示例輸入
this is a test
a
atest
testa
testatest
atest this is
testa this is
testatest this is
this is a test$%a
a word with special chars !@#$%a!@#$%
a word with special chars !@#$%a!@#$% bcd
輸出
a
atest
testa
testatest
this is a test$%a
a word with special chars !@#$%a!@#$%
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/528910.html
標籤:正则表达式sed
