#!/bin/bash
input_exmpl='foo\nbar\nfoo bar\nbar foo\nbbar foo'
echo -e $input_exmpl
echo '--------------'
echo -e $input_exmpl | grep -Pn '^(?=.*\bfoo\b)(?=.*\bbar\b)'
IyEvYmluL2Jhc2gKaW5wdXRfZXhtcGw9J2Zvb1xuYmFyXG5mb28gYmFyXG5iYXIgZm9vXG5iYmFyIGZvbycKCmVjaG8gLWUgJGlucHV0X2V4bXBsCmVjaG8gJy0tLS0tLS0tLS0tLS0tJwplY2hvIC1lICRpbnB1dF9leG1wbCB8IGdyZXAgLVBuICdeKD89LipcYmZvb1xiKSg/PS4qXGJiYXJcYiknCg==