簡體   English   中英

如何從文件中grep一個單詞並僅顯示帶有后綴而非整個行的單詞?

[英]How to grep a word from a file and display only that word with its suffix not the whole line?

如何從文件中grep一個單詞並僅顯示帶有后綴而非整個行的單詞?

這是一個解釋:

文件包括以下內容:(xxxxxx用於隨機數據)

xxxxxx
xxxxxx
word1 word2 word3 device324432 word5 word6
xxxxxx
xxxxxx
word1 word2 word3 device957438546443 word5 word6
xxxxxx
word1 word2 word3 device11128546443 word5 word6
xxxxxx

如果我為設備grep,我會得到整條線。 如果我使用-o grep,我只會得到單詞device(丟棄數字)

我需要的是使這個詞一直到結尾。

device324432
device957438546443
device11128546443 

我使用awk '{print $4}'了效果,但是我想知道是否有“ grep”選項。

-o與匹配后綴的表達式組合。

grep -o 'device[0-9]*'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM