Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash grep command starts with or ends with

I'm after a command that will return results based on a pattern match that starts with or ends with a the given pattern.

This is what i have so far.

"cat input.txt | grep "^in|in$"

My main problem is that i cant get the (or) to work but i can get them to work individually.

Thanks for your help in advance.

like image 601
Daniel Del Core Avatar asked Oct 16 '25 17:10

Daniel Del Core


1 Answers

try this:

grep "^in\|in$" input.txt

by default, grep use BRE, you have to escape the |. Or use grep's -E or -P, in order to avoid escaping those char with special meaning.

P.S, the cat is no necessary.

like image 70
Kent Avatar answered Oct 19 '25 12:10

Kent



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!