On Mar 2, 2010, at 12:55 PM, Garrett D'Amore - sun microsystems wrote:

> This project is an amendment to the Korn Shell 93 Integration project
> (PSARC/2006/550 and PSARC/2007/035, PSARC/2008/094, PSARC/2008/344
> and PSARC/2008/589) specifying the following additional
> interfaces:
> Addition of /usr/bin/xgrep
>
> Bug/RFE Number(s):
>
> 6929154  RFE: Add /usr/bin/xgrep (Augmented regular expressions
>         (conjunction, negation.))
>
>
> Interface                    Stability        Description
> ---------                    ---------        -----------
> /usr/bin/xgrep               Committed        xgrep command
> ksh93 'xgrep' built in       Committed        xgrep command

Before I give this case my +1, I have some questions:

The case's specification should define the syntax of the regular  
expressions the utility accepts.  I suspect that the variants  
requested by the -E, -F, -G, and -P flags can be handled with  
references to the corresponding man pages.  But what is the  
specification for -X mode REs (including the semantics of alternation  
and conjunction)?

What is the difference between lenient and strict pattern  
interpretation?

What is the default for the -H, -h option pair?  The traditional grep  
utility only prefixes matches with file names when there's more than  
one source file.  Is there a way to request compatibility with that  
behavior?  (I think there should be.)

If conflicting options are given on the command line, which one wins?   
The first, the last, is it an error?

                -- Glenn

> Man page for xgrep.1:
>
> = 
> = 
> ======================================================================
> NAME
>  xgrep - search lines in files for matching augmented regular patterns
>
> SYNOPSIS
>  xgrep [ options ] [ pattern ] [ file ... ]
>
> DESCRIPTION
>  The xgrep commands search the named input files for lines
>  containing a match for the given patterns. Matching lines are
>  printed by default. The standard input is searched if no files are
>  given or when the file - is specified.
>
> OPTIONS
>  -G, --basic-regexp
>                  grep mode: basic regular expression
>                  patterns.
>  -E, --extended-regexp
>                  egrep mode: extended regular expression patterns.
>  -X, --augmented-regexp
>                  xgrep mode (default): augmented regular expression
>                  patterns.
>  -P, --perl-regexp
>                  pgrep mode: perl(1) regular expression patterns.
>  -F, --fixed-string
>                  fgrep mode: fixed string patterns.
>  -C, --context[=before[,after]]
>                  Set the matched line context before and after
>                  count. By default only matched lines are printed.
>                  The option value may be omitted. The default value
>                  is 2,2.
>  -c, --count     Only print a matching line count for each file.
>  -e, --expression|pattern|regexp=pattern
>                  Specify a matching pattern. More than one pattern
>                  implies alternation. If this option is specified
>                  then the command line pattern must be omitted.
>  -f, --file=pattern-file
>                  Each line in pattern-file is a pattern, placed
>                  into a single alternating expression.
>  -H, --filename|with-filename
>                  Prefix each matched line with the containing file
>                  name.
>  -h, --no-filename
>                  Suppress containing file name prefix for each
>                  matched line.
>  -i, --ignore-case
>                  Ignore case when matching.
>  -l, --files-with-matches
>                  Only print file names with at least one match.
>  -L, --files-without-matches
>                  Only print file names with no matches.
>  -b, --highlight Highlight matches using the ansi terminal bold
>                  sequence.
>  -v, --invert-match|revert-match
>                  Invert the pattern match sense.
>  -m, --label     All patterns must be of the form label:pattern.
>                  Match and count output will be prefixed by the
>                  corresponding label:.
>  -O, --lenient   Enable lenient pattern interpretation. This is the
>                  default.
>  -x, --line-match|line-regexp
>                  Force patterns to match complete lines.
>  -n, --number|line-number
>                  Prefix each matched line with its line number.
>  -N, --name=name Set the standard input file name prefix to name.
>                  The default value is empty.
>  -q, --quiet|silent
>                  Do not print matching lines.
>  -S, --strict    Enable strict pattern interpretation with
>                  diagnostics.
>  -s, --suppress|no-messages
>                  Suppress error and warning messages.
>  -t, --total     Only print a single matching line count for all
>                  files.
>  -w, --word-match|word-regexp
>                  Force patterns to match complete words.
>  -a              Ignored for GNU compatibility.
>  --help          Print help message.
>
> DIAGNOSTICS
>  Exit status 0 if matches were found, 1 if no matches were found,
>  where -v inverts the exit status. Exit status 2 for other errors
>
> ATTRIBUTES
>     See attributes(5) for descriptions of the  following  attri-
>     butes:
>
>    /usr/bin/xgrep and ksh93 xgrep built in command:
>     ____________________________________________________________
>    |       ATTRIBUTE TYPE         |       ATTRIBUTE VALUE      |
>    |______________________________|____________________________|
>    | Availability                 | SUNWcsu                    |
>    |______________________________|____________________________|
>    | CSI                          | enabled                    |
>    |______________________________|____________________________|
>    | Interface Stability          | Committed                  |
>    |______________________________|____________________________|
>
>
> EXAMPLES
>  Negation ('!' NOT operator):
>   printf '123\n234\n345\n456\n567\n' | xgrep '^(.*4.*)!$'
>
>   will print:
>
>   123
>   567
>
>
>  Conjunction ('&' AND operator):
>
>   printf '123\n234\n345\n456\n' | xgrep '^(.45)&(34.)$'
>
>   will print:
>
>   345
>
> CAVEATS
>  Some expressions of necessity require exponential space and/or
>  time.
>
> BUGS
>  Some expressions may use sub-optimal algorithms. For example,
>  don't use this implementation to compute primes.
>
> SEE ALSO
>  awk(1), ed(1), grep(1), ksh93(1), sed(1), perl(1), regex(3)


Reply via email to