App-Greple-update
view release on metacpan or search on metacpan
lib/App/Greple/update.pm view on Meta::CPAN
greple -Mupdate
Options:
--update replace file content
--with-backup make backup files
--diff produce diff output
-U# specify unified diff context length
--discard simply discard the output
=head1 VERSION
Version 1.04
=head1 DESCRIPTION
This B<greple> module substitute the target file content by command
output. For example, next command replace all words in the file to
uppercase.
greple -Mupdate '\w+' --cm 'sub{uc}' --update file
Above is a very simple example but you can implement arbitrarily
complex function in conjunction with other various B<greple> options.
You can check how the file will be edited by B<--diff> option.
greple -Mupdate '\w+' --cm 'sub{uc}' --diff file
Command B<sdif> or B<cdif> would be useful to see the difference
visually.
greple -Mupdate '\w+' --cm 'sub{uc}' --diff file | cdif
This module has been spun off from L<App::Greple::subst> module.
Consult it for more practical use case.
=head1 OPTIONS
There are two kinds of options for this module, such as C<--diff> and
C<--update::diff>. This is to avoid option name conflicts when used
in combination with other modules. If you are using this module from
another module and want to use the C<--diff> option in it, call as
C<--update::diff>.
=over 7
=item B<--update>
=item B<--update::update>
Update the target file by command output. Entire file content is
produced and any color effects are canceled. Without this option,
B<greple> behaves as normal operation, that means only matched lines
are printed.
File is not touched as far as its content does not change.
The file is also not updated if the output is empty. This is to
prevent the contents of the file from being erased if none of the
match strings are included. If you want to intentionally empty a
file, you need to think of another way.
=item B<--with-backup>[=I<suffix>]
Backup original file with C<.bak> suffix. If optional parameter is
given, it is used as a suffix string. If the file exists, C<.bak_1>,
C<.bak_2> ... are used.
=item B<--discard>
=item B<--update::discard>
Simply discard the command output without updating file. This option
can be used when the output of the command is not needed and only side
effects are expected.
=begin comment
=item B<--create>
=item B<--update::create>
Create new file and write the result. Suffix ".new" is appended to
the original filename.
=end comment
=item B<--diff>
=item B<--update::diff>
Option B<-diff> produce diff output of original and converted text.
Option B<-U#> can be used to specify context length.
=begin comment
=item B<--diffcmd>=I<command>
Specify diff command name used by B<--diff> option. Default is "diff
-u".
=end comment
=back
=head1 INSTALL
=head2 CPANMINUS
$ cpanm App::Greple::update
=head2 GITHUB
$ cpanm https://github.com/kaz-utashiro/greple-update.git
=head1 SEE ALSO
L<App::Greple>, L<https://github.com/kaz-utashiro/greple>
( run in 2.750 seconds using v1.01-cache-2.11-cpan-2398b32b56e )