[svlug] $GREP question
Jesse Monroy
jesse650 at gmail.com
Sun Feb 13 23:20:55 PST 2011
There are two plain solutions you can use. One is with Lexx, the other
is with a scripting language, perl, python, tclsh, even bash.
This is the psuedo-code
while (<fid>) {
$data = $_;
if ($data =~ /begin/) {
flag = 1;
} else if ($data =~ /end/) {
print @collector
} else {
push (@collector, $data)
}
}
That's kinda perl
Lex example is here:
http://accu-usa.org/2001-07.html
On 2/13/11, Eric De Mund <ead-svlug at ixian.com> wrote:
> All,
>
> [$GREP question]
> Hello. How can I $GREP (generically search) a document for a pattern
> and return the records in which it appears, where "record" means either:
>
> 1. content delimited by blank lines (perlpod's "paragraph" definition)
>
> or:
>
> 2. content within some specified "begin" and "end" lines, e.g.
> =begin record
> "The trouble ain't that there is too many fools, but that the
> lightning ain't distributed right."
>
> --Mark Twain
> =end record
>
> My problem is that I have (and want to have) text files that contain
> both kinds of "records", and I want to be able to search them. Outside
> of begin-end pairs, I want the blank-line definition to hold, and inside
> the begin-end pairs, well, I want the begin-end definition to hold.
>
> Is this a solved problem? Manber and Wu's agrep(1) comes close, but an
> agrep(1) delimiter must be a fixed string and not a regular expression.
>
> [meta-question]
> What other forums are good ones for this kind of question?
>
> Thank you!
>
> Eric
> --
> Eric De Mund | Y!: ead0002
> ead at ixian.com | ICQ: 811788
>
> _______________________________________________
> svlug mailing list
> svlug at lists.svlug.org
> http://lists.svlug.org/lists/listinfo/svlug
>
More information about the svlug
mailing list