Hi.
Comments:
1) the cgrep
solution is not trivial, but not difficult, provided one can compile c code. Another grep-like code, skip
( sift - a fast and powerful alternative to grep ) is one of the fastest greps, but I could not entice it to execute as I wished.
2) the suggested solutions in awk
and perl
worked for me.
3) for a sense of completeness and continuing bakunin's note about grep
in AIX with paragraph mode, here are 3 perl
codes that support paragraph mode and should work on AIX and any other system with a recent version of perl
:
#!/usr/bin/env bash
# @(#) s2 Demonstrate extraction by matching token in paragraph.
# Sources, verified 2016.07.05
# tcgrep:
# https://api.metacpan.org/source/CWEST/ppt-0.14/html/commands/grep/tcgrep
# xtcgrep:
# http://cpansearch.perl.org/src/MNEYLON/File-Grep-0.01/Grep.pm
# peg:
# http://www.cpan.org/authors/id/A/AD/ADAVIES/peg-3.10
# Utility functions: print-as-echo, print-line-with-visual-space, debug.
# export PATH="/usr/local/bin:/usr/bin:/bin"
LC_ALL=C ; LANG=C ; export LC_ALL LANG
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C perl tcgrep xtcgrep peg
FILE=${1-data1}
pl " Sample input data file $FILE:"
head $FILE
pl " Results, tcgrep:"
tcgrep -P ';' table7 $FILE
pl " Results, xtcgrep:"
xtcgrep -P '";"' -e table7 $FILE
pl " Results, peg:"
peg -/ ';\n' table7 $FILE
exit 0
producing:
$ ./s2
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 3.16.0-4-amd64, x86_64
Distribution : Debian 8.4 (jessie)
bash GNU bash 4.3.30
perl 5.20.2
tcgrep - ( local: RepRev 1.2, ~/bin/tcgrep, 2012-02-06 )
xtcgrep (local) 1.5
peg (local) 3.10
-----
Sample input data file data1:
CREATE VIEW view1
AS something
FROM table1 ,table2 as A, table3 (something FROM table4)
FROM table5, table6
USING file1
;
CREATE VIEW view1
FROM table1 ,table2 ,table6 ,table9
something
something
-----
Results, tcgrep:
CREATE VIEW view1
FROM table1 ,table2 ,table6 ,table7
something
something
FROM table5 ,table7 (something FROM table4 ,table5(this is something FROM table8)
USING file2
--------------------
-----
Results, xtcgrep:
CREATE VIEW view1
FROM table1 ,table2 ,table6 ,table7
something
something
FROM table5 ,table7 (something FROM table4 ,table5(this is something FROM table8)
USING file2
;
--------------------
-----
Results, peg:
CREATE VIEW view1
FROM table1 ,table2 ,table6 ,table7
something
something
FROM table5 ,table7 (something FROM table4 ,table5(this is something FROM table8)
USING file2
;
As you can see, there may be some cleanup necessary for the separating delimiter in some runs. Some codes may have in-line help that describe options for discarding the output separator lines.
My names for codes is not necessarily the same as the content pointed to by the links.
Best wishes ... cheers, drl