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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With