grep只能顯示匹配搜索模式的單詞嗎?是否有辦法使grep輸出與搜索表達(dá)式匹配的文件中的“單詞”?如果我想在多個文件中找到“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貢獻(xiàn)1796條經(jīng)驗 獲得超7個贊
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.

炎炎設(shè)計
TA貢獻(xiàn)1808條經(jīng)驗 獲得超4個贊
awk
# awk '{for(i=1;i<=NF;i++){if($i~/^th/){print $i}}}' file the the the this thoroughly
- 3 回答
- 0 關(guān)注
- 460 瀏覽
添加回答
舉報
0/150
提交
取消