Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grep - Print line with matching pattern, starting from the matched pattern

For e.g. If I have a file containing:

spam eggs ham

and I do grep <some-flag> "eggs" *

I should get the output as:

eggs ham

and not

spam eggs ham
like image 375
goelakash Avatar asked Oct 20 '25 15:10

goelakash


1 Answers

 $ echo "spam eggs ham" | grep -o 'eggs.*'
 eggs ham
  • grep -o
    This is used to print only the matched portion of text.
  • eggs.*
    This means , eggs followed anything ( dot notify any character and star means zero or more match)
like image 154
P.... Avatar answered Oct 24 '25 19:10

P....



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!