Using AND operator with grep or egrep

OS: RHEL 7.9

In the below example, I want the grep to return only those lines which has both the strings Charles and Dickens in it.
How can I do that ?

$ cat somestrings.txt
hello charles dickens
hello victor hugo
hello charles russel

The OR operator works as shown below. I am looking for a simple way to use AND operator with grep or egrep

$ egrep -i 'Charles|dickens' somestrings.txt
hello charles dickens
hello charles russel
$

You can make use of simple regex .*(greedy regex to make longest possible match) to find both strings in a single line. You can try following code, based on your attempt.

 egrep -i 'Charles.*dickens' Input_file

Thanks,
R. Singh

if order of occurrence is not relevant

$ cat somestrings.txt
hello charles dickens
hello charles russel
hello charles dyckens
hello dickens charles
$
$ # find in either order .... 
$ 
$ grep charles somestrings.txt | grep dickens
hello charles dickens
hello dickens charles banana
$ 

Thank You R.Singh, munkholler for the solutions.

I want to know how exactly does Ravinder Singh's solution egrep -i 'Charles.*dickens' Input_file works.

grep uses regular expressions

And in regular expression world

"." (dot/period) matches any single character
and
"*" (asterix/star) matches zero or more of the preceding character

So, how is .* combination used for AND operation ?

One more question:
What if I want lines with both 'charles dickens' and 'dickens charles' to be returned ?

$ cat somestrings.txt
hello charles dickens
hello victor hugo
hello charles russel
hello dickens charles

charles.*dickens means any characters in between.
In other words, dickens must be to the right of charles.
A real AND would also allow dickens to the left of charles; this can be coded as

egrep -i "charles.*dickens|dickens.*charles" somestrings.txt

Or, as was already suggested, requires two invocations of grep:

grep -i "charles" somestrings.txt | grep -i "dickens"

Being an AND it yields the same result as

grep -i "dickens" somestrings.txt | grep -i "charles"

@george79

recommend you play around with this and read the descriptions given , an excellent tool.

 grep -i 'charles  somestrings.txt | grep -i dickens

I went down this rabbit hole recently when I was solving Wordle.