开发者

grep string after what I specify [duplicate]

This question already has answers here: How to grep for contents after pattern? (8 answers) Closed 7 years ago.

I am using grep and I want to get the data after my string I specify. I want to get the string after开发者_如何学运维 what I specify. If I grep "label:" I get "label: blue label:red label: green". I want to get just the colors. If I say grep -o I get all the labels. If I say -l it says (standard output). Any idea?


you can use sed to eliminate the word label e.g.

grep "label:" | sed s/label://g


Grep is a tool that can only be used for filtering lines of text. To do anything more complex, you probably need a more complex tool.

For example, sed can be used here:

sed 's/.*label: \(.*\)/\1/'

Text like this...

label: blue
llabel: red
label: green label: yellow

Gets turned into this:

blue
red
yellow

As you can see, this sed command only returns what comes after your search pattern, and multiple matches per lines aren't supported.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜