Say I have a file with the following text:
Hello there, How are you?
How can I grep for
are such that the output of
grep looks like:
You can try the following:
grep -Eo "Hello|are" file | sed '$!N;s/\n/,/'
grep -o "Hello\|are" test | tr '\n' ','
-o to only output matching strings, then replace