grep to search some text files, piping the results from one
grep (excluding some lines) to another (matching some lines) + displaying some context using the
-C parameter as shown below:
grep -v "Chapter" *.txt | grep -nE -C1 " leaves? "
This works very well when printing the results, but produces very large files (~ several GB) and takes forever when I write it to file like so:
grep -v "Chapter" *.txt | grep -nE -C1 " leaves? " > out.txt
grepreturns only 1345 lines (according to
wc), printout takes a few seconds
The output in the large output files looks legit, aka actual results from input files.
-Bproduces good output files in the KB size.
- Why is this happening?
- Is there something about the
-Cthat breaks things this way?
- Or is there a different issue I am overlooking?
Any hints appreciated! Running this in the MacOS terminal. I was following this man.