sggrep(1)

NAME
sggrep - nSGML selection and searching tool

SYNOPSIS
usage:
   sggrep [<options>] -q query [ -s sub-query] [-t regexp] file...
     or
   sggrep [<options>] query [[sub-query] regexp] [[--] file...]
   query: pattern on items to select, basically path based with terms
     separated by /, <term>:=<GI><cond>?'*'?
                     <GI>:=<elementName>|'.'
             <cond>:='['<index>|<atests>|<index> <atests>']'
             <index>:=<number>
             <atests>:=<atest>(' '<atest>)*
             <atest>:=<aname>( ['='|'!='] <aval> )?
     Aname and aval are as per SGML, except that if the -r flag is given,
     aval are regular expressions.
     A GI of . matches any tag. A condition with an index matches only the
     index'th sub-element of the enclosing element. Attribute tests are not
     exhaustive, and will match against both explicitly present and defaulted
     attribute values, using string equality. Bare anames are satisfied by
     ANY value, explicit or defaulted. Terms ending with * match
     any number of links in the chain, including 0.
   sub-query: if present, selects sub-elements of query-selected item for
               regexp to match
   regexp: Regular expression to match against text directly contained in
            query-selected item (if no sub-query) or in any sub-query selected
        sub-element of query-selected item.
            If empty (i.e. '') matches anything, including empty elements,
            indeed this is the ONLY way to get empty elements if required. When using the second, terse, form, the '--' is required if regexp and/or sub-query are omitted. Other options: -d ddb-file: Take Dtd from specified ddb file -o out-file: Put output to specified file
   -v: invert sense of sub-query+regexp
   -n: don't force a newline between output matches
   -r: attribute values in queries are regular expressions
   -mq mark-query: is an NSL query which tells us which subelements of
                  elements matching <query> are going to be 'marked'.
                  Sub-elements matching <mark-query> are 'marked' if they
                  in turn contain a sub element which matches
                  <sub-query> which includes text matching <regexp>
                  mt must be specified if mq is
   -mt mark-tag: indicates which tag is to be used to wrap the marked elements.

   -a element-name: Give an element name to act as a toplevel element
                    in which matching elements will be embedded.
                    (in NSL mode this tag must be in the DTD)

DESCRIPTION
The material below may be out of date: consult LT XML documentation please. sggrep is an nSGML-aware version of ``grep''. Sggrep allows one to select a set of SGML elements from a document and to search for a string regular expression within these selected elements. It is a filter, ie it reads from stdin and writes to stdout.

DESCRIPTION: Parameters

<query>
    is an NSL query which selects the set of matching elements from the input stream.

<sub-query>
    is an optional NSL query which if present, selects sub-elements of query-selected item for regexp to match.

<regexp>
    A regular expression to match against text directly contained in query-selected item (if no sub-query) or in any sub-query selected sub-element of query-selected item. If empty (i.e. '') matches anything, including empty elements, indeed this is the ONLY way to get empty elements if required.

DESCRIPTION: Input/Output
Description of the input/output files involved in this program.

Input ==> NSL input file : [stdin]

Output ==> List of matching SGML elements : [stdout]

OPTIONS

-d <ddb-file>
    is the name of a file containing a representation of a DTD. Can be used if the DTD is not specified in the input document iself.

-v  Complement operation. If this option is specified then only elements which do match the <query>, but do not match the <subquery> plus <regexp> combination, are output. Default is normal matching.

-r  Interpret values of attributes in queries as regular expressions. Default is to treat attribute values as plain strings.

-n  Don't force a newline between output matches.

-h  Print out usage information about sggrep.

EXAMPLES
sggrep ".*/name" ".*" < temp.sgm
    prints out a list of all the <name> elements anywhere
    in the input document.
sggrep ".*/name" "Holmes" < temp.sgm
    prints out a list of all the <name> elements which
    contain the string "Holmes".
sggrep ".*/sentence" "./name" "Ho.*s" < temp.sgm
    prints out a list of all the <sentence> elements which
    contain    a <name> element which match the regular
    expression, i.e. which contain "Ho" and "s".

NSL QUERIES
 NSL queries are patterns on items (SGML elements) to select. A query describes a path from the root of the document to the desired element and is basically a path based with terms separated by / as follows:
        <query> := <term> ('/' <term>)*
        <term> := <bTerm> '*'?
        <bTerm> := <aTerm> ( '|' <aTerm> )*
        <aTerm> := <GI> <cond>?
        <GI> := <elementName> | '.'
        <cond> := '[' <index>|<atests>|<index> <atests>']'
        <index> := <number>
        <atests> := <atest> (' ' <atest>)*
        <atest> := <aname> ('=' <aval>)?
Aname and aval are as per SGML, except that if the -r flag is given, aval is a regular expression.
<term>s which consist of a number of <bTerm>s separated by '|' match against any element which matches one of the <bTerms>.
A GI of . matches any tag. A condition with an index matches only the index'th sub-element of the enclosing element. Attribute tests are not exhaustive, and will match against both explicitly present and defaulted attribute values, using string equality. Bare anames are satisfied by ANY value, explicit or defaulted. Terms ending with * match any number of links in the chain, including 0.

SEE ALSO
ltxml(1), regexp(3), ltxml-query(5)

AUTHOR
Henry Thompson (ht@cogsci.ed.ac.uk)
David McKelvie (dmck@cogsci.ed.ac.uk)
Language Technology Group, Human Communication Research Centre, Edinburgh University,
2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND
Tel:(44) 131 650-4630
Fax:(44) 131 650-4587 email: dmck@cogsci.ed.ac.uk

Comments, suggestions, and bug reports are always welcome.