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:
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
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