In the below text file, I want to find the lines which has the string JOHN , KATE and STEVE in it.
The logic is to grep with an AND condition ie. get all lines with JOHN AND KATE AND STEVE
$ cat sometext.txt
PHILIP worked in HR
JOHN along with KATE fixed several IT issues. But, Steve got all the credit
JOHN worked in IT Department
KATE worked in the IT Department
STEVE worked in IT department
expected output: JOHN along with KATE fixed several IT issues. But, Steve got all the credit
The following will work. But I need to grep multiple times. Is there another quick way using grep,egrep, awk, sed , ...etc ?
$ cat sometext.txt | grep -i JOHN | grep -i KATE| grep -i STEVE
JOHN along with KATE fixed several IT issues. But, Steve got all the credit
Note that with your code (and either of the above) "skate" will be accepted as a match for KATE and "Stevenson" will be accepted as a match for STEVE. So, if you don't want:
Last winter, Johnny skated on the Stevens lake reservoir.
to be selected, you need to clarify your requirements.