App-Greple
view release on metacpan or search on metacpan
- Add --version option
10.02 2026-01-09T04:59:40Z
- Suppress experimental::vlb warning for Variable Length Lookbehind
- Use eval for backward compatibility with older Perl versions
10.01 2025-12-31T01:30:39Z
- Add escape sequence support (\t, \n, \r, \f) to --blockend option
- Unify escape sequence handling with shared expand_escape() function
10.00 2025-12-11T03:23:27Z
- Bump major version to 10.00 to indicate minimum Perl version requirement
change from 5.14 to 5.24
- Add --block-number (-b) option to show block numbers
- Add --blockstyle support to --separate option
- Allow "\f" in --format string
- Improve DEFINE pattern support for -f option
greple --icode=utf8,euc-jp,shift-jis,7bit-jis
### add to guessing code set / èªåå¤å®ããã³ã¼ãã追å ãã
greple --icode=+euc-kr
---
## Filter / ãã£ã«ã¿ã¼
### expand tabs before seach / ã¿ããå±éãã¦ããæ¤ç´¢ãã
greple -n --if=expand
# give better looking for tab indented text
### find from EXIF data / EXIF æ
å ±ãæ¤ç´¢ãã
greple --if='env LC_ALL=en_US exif -x /dev/stdin' 'Image_Description|Manufacturer' *.jpg
---
## Print Function / ããªã³ã颿°
--pf=filter post-process filter command
--noif disable the default input filter
RUNTIME FUNCTION
--begin=func call a function before starting the search
--end=func call a function after completing the search
--prologue=func call a function before executing the command
--epilogue=func call a function after executing the command
--postgrep=func call a function after each grep operation
--callback=func callback function for each matched string
OTHER
--usage[=expand] show this help message
--version show version
--exit=n set the command exit status
--norc skip reading startup file
--man display the manual page for the command or module
--show display the module file contents
--path display the path to the module file
--error=action action to take after a read error occurs
--warn=type runtime error handling type
--alert [name=#] set alert parameters (size/time)
-d flags display info (f:file d:dir c:color m:misc s:stat)
Specify the negative match pattern. Because it does not affect the
bare pattern argument, you can narrow down the search result like
this.
greple foo file
greple foo file -v bar
greple foo file -v bar -v baz
In the above pattern options, space characters are treated specially.
They are replaced by the pattern which matches any number of white
spaces including newline. So the pattern can expand to multiple
lines. Next commands search the series of word `foo` `bar` `baz`
even if they are separated by newlines.
greple -e 'foo bar baz'
This is done by converting pattern `foo bar baz` to
`foo\s+bar\s+baz`, so that word separator can match one or more white
spaces.
As for Asian wide characters, pattern is cooked as zero or more white
greple -m 20,,,-10
- **-A**\[_n_\], **--after-context**\[=_n_\]
- **-B**\[_n_\], **--before-context**\[=_n_\]
- **-C**\[_n_\], **--context**\[=_n_\]
Print _n_-blocks before/after matched string. The value _n_ can be
omitted and the default is 2. When used with `--paragraph` or
`--block` option, _n_ means number of paragraph or block.
Actually, these options expand the area of logical operation. It
means
greple -C1 'foo bar baz'
matches following text.
foo
bar
baz
- **--inside**=_pattern_
- **--outside**=_pattern_
Option `--inside` and `--outside` limit the text area to be matched.
For simple example, if you want to find string `and` not in the word
`command`, it can be done like this.
greple --outside=command and
The block can be larger and expand to multiple lines. Next command
searches from C source, excluding comment part.
greple --outside '(?s)/\*.*?\*/'
Next command searches only from POD part of the perl script.
greple --inside='(?s)^=.*?(^=cut|\Z)'
When multiple **inside** and **outside** regions are specified, those
regions are mixed up in union way.
sub function {
my %arg = @_;
my $filename = delete $arg{&FILELABEL};
$arg{key1}; # 1
$arg{key2}; # "val2"
$_; # contents
}
## OTHERS
- **--usage**\[=_expand_\]
**Greple** print usage and exit with option `--usage`, or no valid
parameter is not specified. In this case, module option is displayed
with help information if available. If you want to see how they are
expanded, supply something not empty to `--usage` option, like:
greple -Mmodule --usage=expand
- **--version**
Show version.
- **--exit**=_number_
When **greple** executed normally, it exit with status 0 or 1 depending
on something matched or not. Sometimes we want to get status 0 even
if nothing matched. This option set the status code for normal
option --line --le &line=$<shift>
is defined, command
greple --line 10,20-30,40
will be evaluated as this:
greple --le &line=10,20-30,40
- **expand** _name_ _string_
Define local option _name_. Command **expand** is almost same as
command **option** in terms of its function. However, option defined
by this command is expanded in, and only in, the process of
definition, while option definition is expanded when command arguments
are processed.
This is similar to string macro defined by following **define**
command. But macro expansion is done by simple string replacement, so
you have to use **expand** to define option composed by multiple
arguments.
- **define** _name_ string
Define macro. This is similar to **option**, but argument is not
processed by _shellwords_ and treated just a simple text, so
meta-characters can be included without escape. Macro expansion is
done for option definition and other macro definition. Macro is not
evaluated in command line option. Use option directive if you want to
use in command line,
@list;
}
You can use next command to search pattern included in odd number
lines.
% greple --inside '&odd_line' pattern files...
# MODULE
You can expand the **greple** command using module. Module files are
placed at `App/Greple/` directory in Perl library, and therefor has
**App::Greple::module** package name.
In the command line, module have to be specified preceding any other
options in the form of **-M**_module_. However, it also can be
specified at the beginning of option expansion.
If the package name is declared properly, `__DATA__` section in the
module file will be interpreted same as `.greplerc` file content. So
you can declare the module specific options there. Functions declared
in the module can be used from those options, it makes highly
expandable option/programming interaction possible.
Using `-M` without module argument will print available module list.
Option `--man` will display module document when used with `-M`
option. Use `--show` option to see the module itself. Option
`--path` will print the path of module file.
See this sample module code. This sample defines options to search
from pod, comment and other segment in Perl script. Those capability
can be implemented both in function and macro.
lib/App/Greple/dig.pm view on Meta::CPAN
use warnings;
1;
__DATA__
##
## directories
##
expand is_repository ( -name .git -o -name .svn -o -name RCS -o -name CVS )
expand is_environment ( -name .vscode )
expand is_temporary ( -name .build -o -name _build )
expand is_hugo_gen ( -path */resources/_gen )
expand is_artifacts ( -name node_modules )
##
## files
##
expand is_dots -name .*
expand is_version -name *,v
expand is_backup ( -name *~ -o -name *.swp )
expand is_image ( -iname *.jpg -o -iname *.jpeg -o \
-iname *.gif -o -iname *.png -o \
-iname *.ico -o \
-iname *.heic -o -iname *.heif -o \
-iname *.svg -o \
-iname *.tif \
)
expand is_archive ( -iname *.tar -o -iname *.tar.gz -o -iname *.tbz -o -iname *.tgz -o \
-name *.a -o -name *.zip \
)
expand is_pdf -iname *.pdf
expand is_db ( -name *.db -o -iname *.bdb )
expand is_minimized ( -name *.min.js -o -name *.min.*.js -o \
-name *.min.css -o -name *.min.*.css )
expand is_others ( -name *.bundle -o -name *.dylib -o -name *.o -o \
-name *.fits )
option --dig -Mfind \
$<move> \
( \
( is_repository -o \
is_environment -o \
is_temporary -o \
is_hugo_gen -o \
is_artifacts \
script/greple view on Meta::CPAN
--pf=filter post-process filter command
--noif disable the default input filter
RUNTIME FUNCTION
--begin=func call a function before starting the search
--end=func call a function after completing the search
--prologue=func call a function before executing the command
--epilogue=func call a function after executing the command
--postgrep=func call a function after each grep operation
--callback=func callback function for each matched string
OTHER
--usage[=expand] show this help message
--version show version
--exit=n set the command exit status
--norc skip reading startup file
--man display the manual page for the command or module
--show display the module file contents
--path display the path to the module file
--error=action action to take after a read error occurs
--warn=type runtime error handling type
--alert [name=#] set alert parameters (size/time)
-d flags display info (f:file d:dir c:color m:misc s:stat)
script/greple view on Meta::CPAN
}
my $need_color = (($opt_color eq 'always')
or (($opt_color eq 'auto') and (!$opt_o and -t STDOUT)));
if (!$need_color) {
$Getopt::EX::Colormap::NO_COLOR = 1;
}
my %_esc = ( t => "\t", n => "\n", r => "\r", f => "\f" );
sub expand_escape {
$_[0] =~ s{\\(.)}{$_esc{$1} // $1}egr;
}
$_ = expand_escape($_) for values %opt_format;
my $blockend = "--";
if (defined $opt_blockend) {
$blockend = expand_escape($opt_blockend);
}
my $_file = sub { $color_handler->color('FILE' , sprintf($opt_format{FILE}, $_[0])) };
my $_line = sub { $color_handler->color('LINE' , sprintf($opt_format{LINE}, $_[0])) };
my $_block = sub { $color_handler->color('BLOCK', sprintf($opt_format{BLOCK}, $_[0])) };
my $_text = sub { $color_handler->color('TEXT' , $_[0]) };
my $_blockend = $color_handler->color('BLOCKEND', $blockend);
my $_top = $color_handler->color('TOP' , $opt_frame_top);
my $_middle = $color_handler->color('MIDDLE' , $opt_frame_middle);
my $_bottom = $color_handler->color('BOTTOM' , $opt_frame_bottom);
script/greple view on Meta::CPAN
this.
greple foo file
greple foo file -v bar
greple foo file -v bar -v baz
=back
In the above pattern options, space characters are treated specially.
They are replaced by the pattern which matches any number of white
spaces including newline. So the pattern can expand to multiple
lines. Next commands search the series of word C<foo> C<bar> C<baz>
even if they are separated by newlines.
greple -e 'foo bar baz'
This is done by converting pattern C<foo bar baz> to
C<foo\s+bar\s+baz>, so that word separator can match one or more white
spaces.
As for Asian wide characters, pattern is cooked as zero or more white
script/greple view on Meta::CPAN
=item B<-A>[I<n>], B<--after-context>[=I<n>]
=item B<-B>[I<n>], B<--before-context>[=I<n>]
=item B<-C>[I<n>], B<--context>[=I<n>]
Print I<n>-blocks before/after matched string. The value I<n> can be
omitted and the default is 2. When used with C<--paragraph> or
C<--block> option, I<n> means number of paragraph or block.
Actually, these options expand the area of logical operation. It
means
greple -C1 'foo bar baz'
matches following text.
foo
bar
baz
script/greple view on Meta::CPAN
=item B<--inside>=I<pattern>
=item B<--outside>=I<pattern>
Option C<--inside> and C<--outside> limit the text area to be matched.
For simple example, if you want to find string C<and> not in the word
C<command>, it can be done like this.
greple --outside=command and
The block can be larger and expand to multiple lines. Next command
searches from C source, excluding comment part.
greple --outside '(?s)/\*.*?\*/'
Next command searches only from POD part of the perl script.
greple --inside='(?s)^=.*?(^=cut|\Z)'
When multiple B<inside> and B<outside> regions are specified, those
regions are mixed up in union way.
script/greple view on Meta::CPAN
$arg{key2}; # "val2"
$_; # contents
}
=head2 OTHERS
=over 7
=item B<--usage>[=I<expand>]
B<Greple> print usage and exit with option C<--usage>, or no valid
parameter is not specified. In this case, module option is displayed
with help information if available. If you want to see how they are
expanded, supply something not empty to C<--usage> option, like:
greple -Mmodule --usage=expand
=item B<--version>
Show version.
=item B<--exit>=I<number>
When B<greple> executed normally, it exit with status 0 or 1 depending
on something matched or not. Sometimes we want to get status 0 even
if nothing matched. This option set the status code for normal
script/greple view on Meta::CPAN
option --line --le &line=$<shift>
is defined, command
greple --line 10,20-30,40
will be evaluated as this:
greple --le &line=10,20-30,40
=item B<expand> I<name> I<string>
Define local option I<name>. Command B<expand> is almost same as
command B<option> in terms of its function. However, option defined
by this command is expanded in, and only in, the process of
definition, while option definition is expanded when command arguments
are processed.
This is similar to string macro defined by following B<define>
command. But macro expansion is done by simple string replacement, so
you have to use B<expand> to define option composed by multiple
arguments.
=item B<define> I<name> string
Define macro. This is similar to B<option>, but argument is not
processed by I<shellwords> and treated just a simple text, so
meta-characters can be included without escape. Macro expansion is
done for option definition and other macro definition. Macro is not
evaluated in command line option. Use option directive if you want to
use in command line,
script/greple view on Meta::CPAN
}
You can use next command to search pattern included in odd number
lines.
% greple --inside '&odd_line' pattern files...
=head1 MODULE
You can expand the B<greple> command using module. Module files are
placed at F<App/Greple/> directory in Perl library, and therefor has
B<App::Greple::module> package name.
In the command line, module have to be specified preceding any other
options in the form of B<-M>I<module>. However, it also can be
specified at the beginning of option expansion.
If the package name is declared properly, C<__DATA__> section in the
module file will be interpreted same as F<.greplerc> file content. So
you can declare the module specific options there. Functions declared
in the module can be used from those options, it makes highly
expandable option/programming interaction possible.
Using C<-M> without module argument will print available module list.
Option C<--man> will display module document when used with C<-M>
option. Use C<--show> option to see the module itself. Option
C<--path> will print the path of module file.
See this sample module code. This sample defines options to search
from pod, comment and other segment in Perl script. Those capability
can be implemented both in function and macro.
( run in 3.009 seconds using v1.01-cache-2.11-cpan-5623c5533a1 )