This snippet:
# Utility functions: print-as-echo, print-line-with-visual-space.
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
pl " Input data file $FILE:"
head -v -n 20 $FILE
pl " Expected output on file $E:"
head -v $E
pl " Results:"
cgrep -V -D -w '<!--START OF FILE -->' +2 +w 'x x x x x x x' 'meta' $FILE
produces:
-----
Input data file data1:
==> data1 <==
<!--START OF FILE -->
random text
<meta> more random text </meta>
x x x x x x x
more random text
that I dont need
x x x x x x x
I need everything
from this point
-----
Expected output on file expected-output1:
I need everything
from this point
onwards
...
-----
Results:
I need everything
from this point
onwards
...
This omits (-V) a window beginning (-w) with '...START...', and ending (+w) with the second occurrence (+2) of a string '...x x...' that has the string 'meta' inside the window.
On a system like:
OS, ker|rel, machine: Linux, 3.16.0-4-amd64, x86_64
Distribution : Debian 8.9 (jessie)
bash GNU bash 4.3.30
Some details for cgrep:
cgrep shows context of matching patterns found in files (man)
Path : ~/executable/cgrep
Version : 8.15
Type : ELF 64-bit LSB executable, x86-64, version 1 (SYS ...)
Home : http://sourceforge.net/projects/cgrep/ (doc)
Although one would need to get and compile cgrep, I have had no trouble doing that on 32-bit or 64-bit systems, and it is available on macOS (High Sierra) with brew. The execution time is on a par with GNU grep.
Best wishes ... cheers, drl
f;
to!f;
– Sundeep Dec 24 '17 at 12:23