亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

grep只能顯示匹配搜索模式的單詞嗎?

grep只能顯示匹配搜索模式的單詞嗎?

grep只能顯示匹配搜索模式的單詞嗎?是否有辦法使grep輸出與搜索表達式匹配的文件中的“單詞”?如果我想在多個文件中找到“th”的所有實例,我可以這樣做:grep "th" *但是輸出將是類似的(粗體是由我);some-text-file : the cat sat on the mat   some-other-text-file : the quick brown fox   yet-another-text-file : i hope this explains it thoroughly使用相同的搜索,我希望它輸出的是:the the the this thoroughly這有可能使用grep嗎?還是使用另一種組合的工具?
查看完整描述

3 回答

?
蕭十郎

TA貢獻1815條經驗 獲得超13個贊

試試grep-o

grep?-oh?"\w*th\w*"?*
-h,?--no-filename
????Suppress?the?prefixing?of?file?names?on?output.?This?is?the?default
????when?there?is?only??one??file??(or?only?standard?input)?to?search.
-o,?--only-matching
????Print??only??the?matched?(non-empty)?parts?of?a?matching?line,
????with?each?such?part?on?a?separate?output?line.


查看完整回答
反對 回復 2019-07-19
?
PIPIONE

TA貢獻1829條經驗 獲得超9個贊

只是awk不需要工具的組合。

# awk '{for(i=1;i<=NF;i++){if($i~/^th/){print $i}}}' file
the
the
the
this
thoroughly


查看完整回答
反對 回復 2019-07-19
  • 3 回答
  • 0 關注
  • 1147 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號