Table of Contents


grecce - print lines matching a pattern.


grecce [OPTIONS] FILE ...


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


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.
  • 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.
    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.


    +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.
    < >.

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

    If an alternative can’t match, irrespective of the subsequent concatenation, then terminate futile trial repetitions.
    Avoid futile trial solutions, involving repetitions of anchored alternatives, which must consume data.
    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.
    Check whether there’s no possibility of consuming some of the input data.
    Greedily consume data, only up to the limit beyond which, future requirements would be compromised.
    Permit alternatives to be re-ordered, in an attempt to process the cheapest first.
    Unroll repetitions of singleton alternatives; this doesn’t affect the result.
    Rather than performing an exhaustive search for the optimal choice amongst alternatives, merely select the first that matches; conform to Perl rather than Posix.
    When the number of repetitions of a group of alternatives is precisely specified, check the availability of the resulting minimum data-requirement.


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

    Generic Program-information

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


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


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


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

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


    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,""))



    Written by Dr. Alistair Ward.


    Reporting Bugs

    Report bugs to <>.

    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 © 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 < >.

    See Also

    Table of Contents