Table of Contents

Name

grecce - print lines matching a pattern.

Synopsis

grecce [OPTIONS] FILE ...

Description

Searches the named input FILEs (or standard input if no files are named, or if FILE is defined as a single hyphen-minus (-)), for lines containing a match for regex.

By default, prints the matching lines.

Supported Regular-expression Syntax

Options

General Output Control

-c, --count
Print only a count of matching lines per file.
-l, --files-with-matches
List names of files containing at least one match.
-L, --files-without-match
List names of files not containing any matches.
--verbose
  • Shows how the input data was captured by regex.
  • The output is a triple (prefix, data consumed by regex, suffix): If data is consumed either before, by, or after regex, then the corresponding section contains Just, otherwise it contains Nothing.
  • If the regex matched, the central section, following Just, details the consumption of each term in the regex, in terms of another triple; (printed term, offset, input-data).
  • Because of the inherently recursive nature of a regex, the output is actually tree-structured.
  • This is an addition to the options available in egrep, & provides a powerful insight into the inner workings of the regex-engine; useful for debugging the regex.
  • Output Line Prefix Control

    -n, --number
    Prepend the line-number of the input, to the output.

    Matching Control

    -e regex, --regexp=regex
    Define the regex.
    -f file-name, --file=file-name
    Read the regex from file-name.
    -v, --invert-match
    Select non-matching lines.
    --complyStrictlyWithPosix=Bool
    Define the offset of input-data, corresponding to a capture-group which matched zero times, as the artificial value -1 specified by Posix. This is an addition to the options available in egrep, & is of relatively little use.

    Performance

    +RTS -N [Cores] [-H Minimum heap-size] -RTS
    If the executable has been linked with the threaded GHC-runtime, use Cores simultaneous threads (defaulting to the number of CPU-cores available), to process alternative sub-expressions and multiple files in parallel; When specifying this option, it is usually beneficial, given sufficient resources, to suggest a large minimum heap-size for the garbage-collector.
    <https://www.haskell.org/ghc/docs/latest/html/users_guide/using-smp.html#parallel-options >.

    These options are rather esoteric & not normally required.
    Bool can be defined as either "True" or "False".

    --abortTrialRepetitionsOnInherentFailure=Bool
    If an alternative can’t match, irrespective of the subsequent concatenation, then terminate futile trial repetitions.
    --catchIncompatibleAnchors=Bool
    Avoid futile trial solutions, involving repetitions of anchored alternatives, which must consume data.
    --checkExistenceOfInelasticTail=Bool
    If regex ends in one or more meta-data, whose repetition-range is precisely defined, check that this sequence exists at the end of the input data.
    --checkForUnconsumableData=Bool
    Check whether there’s no possibility of consuming some of the input data.
    --moderateGreed=Bool
    Greedily consume data, only up to the limit beyond which, future requirements would be compromised.
    --permitReorderingOfAlternatives=Bool
    Permit alternatives to be re-ordered, in an attempt to process the cheapest first.
    --unrollRepeatedSingletonAlternative=Bool
    Unroll repetitions of singleton alternatives; this doesn’t affect the result.
    --useFirstMatchAmongAlternatives=Bool
    Rather than performing an exhaustive search for the optimal choice amongst alternatives, merely select the first that matches; conform to Perl rather than Posix.
    --validateMinConsumptionOfAlternatives=Bool
    When the number of repetitions of a group of alternatives is precisely specified, check the availability of the resulting minimum data-requirement.

    Match-preference

    --preferAlternativesWhichFeedTheGreedy=Bool
    Prefer solutions in which the choice of alternatives directs data from non-greedy to greedy consumers.
    --preferAlternativesWhichMimickUnrolling=Bool
    Prefer solutions in which the choice of alternatives consumes data like the unrolled repeatable group.
    --preferFewerRepeatedAlternatives=Bool
    Prefer solutions employing fewer repetitions of alternatives, to discourage the capture of null lists.

    Generic Program-information

    --version
    Output version-information & exit.
    -?, --help
    Display help & exit.
    --printCurrentSettings
    Display the currently defined options & then exit.

    Test

    --assert=file
    Confirms the assertions in the specified file from the data-directory of the distribution; then exits.

    Exit-status

    0 on success, and >0 if an error occurs.

    Examples


    echo ’Function Alley’ | grecce ’n\sA’
    Function Alley
    


    echo ’Function  Alley’ | grecce --verbose ’[[:alpha:]]+’
    (Just (.*?,0,""),Just [([[:alpha:]]+,0,"Function")],Just (.*,8,"  Alley"))
    

    Pathological


    echo ’aaa’ | grecce --verbose ’^(a?){3}(a){3}$’
    (Nothing,Just [[[(’a’?,0,"")],[(’a’?,0,"")],[(’a’?,0,"")]],[[(’a’,0,"a")],[(’a’,1,"a")],[(’a’,2,"a")]]],Nothing)
    


    echo ’azazaz’ | grecce --verbose ’^(.*z){3}$’
    (Nothing,Just [[[(.*,0,"a"),(’z’,1,"z")],[(.*,2,"a"),(’z’,3,"z")],[(.*,4,"a"),(’z’,5,"z")]]],Nothing)
    


    echo ’aaaaaa’ | grecce --verbose ’^a*a+a{2,}a{3,}$’
    (Nothing,Just [(’a’*,0,""),(’a’+,0,"a"),(’a’{2,},1,"aa"),(’a’{3,},3,"aaa")],Nothing)
    


    echo ’aaaaaaaabc’ | grecce --verbose ’(a|a{2})*c’
    (Just (.*?,0,"aaaaaaaab"),Just [[],(’c’,9,"c")],Just (.*,10,""))
    

    Files

    Author

    Written by Dr. Alistair Ward.

    Bugs

    Reporting Bugs

    Report bugs to <grecce@functionalley.com>.

    Known Bugs

    There is no support for either Back-references or Case-insensitivity.

    The only support for Zero-width assertions, is for Anchors.

    File-reading is rather slow, due to the inability to optimise the underlying polymorphic regex-engine for Characters.

    Copyright

    Copyright © 2010-2015 Dr. Alistair Ward

    This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/ >.

    See Also


    Table of Contents