I can use vim / ex to grep a file using the following invocation:
ex -c'g/foo/p' -cq -s afile.txt
I'd really like to use a similar command to grep some text from stdin. I thought the following command should work, but it produces no output:
cat afile.txt | ex -c'g/foo/p' -cq -s -
The same thing happens if I use vim -e
instead of ex
:
cat test.md | vim -e -c'g/foo/p' -cq -s -
Is there any way that I can force ex to read its initial buffer from stdin and print output to stdout, so that it can be used within a Unix pipe-line?