incava.org

NAME

modifile - applies Perl substitution expressions to file names and contents


SYNOPSIS

    modifile 's/print/write/g' *.java
    modifile --execute 'tr/A-Z/a-z/' README.txt
    modifile --noexecute --readonly "co" --file substitutions.lst *.h *.cpp


DESCRIPTION

This application applies Perl substitution expressions to files, modifying the name and/or the contents of the file and making backup versions of the original file as needed. It also checks for write permissions before applying any changes, and provides a list of the files that would have been changed, yet did not have write permission.


OPTIONS

--backup, --nobackup
Backup the changed files. The default is --backup.

--basenames, --nobasenames
Change the base names of the files, that is, foo.txt of the full name /home/jrandom/proj/bar/foo.txt. The default is --basenames. See also the --dirnames option.

--confirm
Process files interactively, getting user confirmation when the substitutions would result in a change.

--contents, --nocontents
Change the contents of the files. The default is --contents.

--count NUM
Stop substitutions after count lines have been modified.

--dirnames, --nodirnames
Change the directory names of the files, that is, /home/jrandom/proj/bar of the full name /home/jrandom/proj/bar/foo.txt. The default is --dirnames. See also the --basenames option.

--execute, --noexecute
Whether to change the file names and contents. The default is --execute.

--file FILE
Read the given file, which contains a list of all expressions to be evaluated, in the format:
    s/foo/bar/g
    tr/a-z/A-Z/
    # make fooBar into FOO_BAR:
    s/([a-z]+)([A-Z])/\U$1_$2/g

Both spaces and script-style comments (i.e., beginning with '#') are allowed in the substitution file.

If the --file option is not used, the substitution expression will be assumed to be the next command-line argument after all options have been processed.

--quiet
Run with minimal output.

--readonly COMMAND
If a file is read-only, execute the given command on the file. For example:
    --readonly "chmod u+w"
    --readonly "p4 edit" (set status to editable in the Perforce CM system)

--verbose
Run with debugging output.


EXAMPLES

    % modifile --execute --count 1 's/^(?=[^\s#])/using namespace std;\n\n/m' *.cpp

Inserts ``using namespace std;'' before the first line that starts with something other than a blank line or '#' (preprocessor directive).

    % modifile --nodirnames --nocontents 'tr/A-Z/a-z/' *

Changes all file names to lowercase (but not the directory names).

    % modifile --dirnames --nobasenames --nocontents 's/(?<![a-z])([a-z])/\u$1/g' *

Changes all directory names to title case (``Like_This/And:This''). Does not change file base names or contents.


AUTHOR

Jeff Pace <jpace@incava.org>


COPYRIGHT

Copyright (c) 2005, Jeff Pace.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Valid HTML 4.01!

Valid CSS!