Package: pyreutil
pyreutilPyreutilis a simple command line utiliy to bulk edit filenames or text files using regex.Getting startedUsageCommandsExamplesGetting startedYou can install the package using pip by running the following command:$pipinstallpyreutilOr for manual installation using the CLI$gitclonehttps://github.com/michsun/pyreutil.git
$cdpyreutil
$pythonsetup.pyinstallUsageIf installed using pip or CLI, you can run the utility using the following command structure.$pyreutil[-for-t][path_to_directory_or_file][arguments...]Otherwise, if downloaded directly, go to thepyreutilfolder and use the following commands:$python-mpyreutil[-for-t][path_to_directory_or_file][arguments...]OR
$python3-mpyreutil[-for-t][path_to_directory_or_file][arguments...]CommandsThe full list of commands is listed below:usage: pyreutil [-h] [-t TEXTFILES | -f FILENAMES] [-a APPEND] [-af APPEND_FILE] [-c] [-d] [-i]
                [-l LAMBDA_FUNC] [-r REPLACE] [-rf REPLACE_FILE] [-g GROUP] [-rm REMOVE] [-s SEARCH]
                [-si] [-w] [-md]

pyreutil - A python command line utility for searching and modifying files and filenames using regex.

optional arguments:
  -a APPEND, --append APPEND
                        text to append
  -af APPEND_FILE, --append-file APPEND_FILE
                        appends file contents
  -c, --copy            saves changes as a copy of the original directory/file
  -d, --deep            search subdirectories if a directory is given
  -f FILENAMES, --filenames FILENAMES
                        filenames source
  -g GROUP, --group GROUP
                        integer representing the group to replace. Must be used with -s --search
  -h, --help            show this help message and exit
  -i, --inplace         save changes to the existing directory/file
  -l LAMBDA_FUNC, --lambda-func LAMBDA_FUNC
                        code string to execute in a lambda function
  -rm REMOVE, --remove REMOVE
                        removes regex matches
  -md, --remove-md-links
                        removes markdown links and replaces it with the link name
  -w, --remove-whitespaces
                        removes redundant whitespaces (repeat, leading, trailing, and spaces before a
                        period or comma)
  -r REPLACE, --replace REPLACE
                        string to replace searches with. Must be used with -s --search
  -rf REPLACE_FILE, --replace-file REPLACE_FILE
                        file containing contents to replaces regex searches with. Must be used with -s
                        --search
  -s SEARCH, --search SEARCH
                        searches for regex matches
  -si, --silence        silences the output
  -t TEXTFILES, --textfiles TEXTFILES
                        text sourceIf functions are used in conjunction, they are processed in the following order:RemoveAppend/Append file contentsSearch and replace with string/file contents/group/lambda function.Remove redundant whitespacesExamplesSearch and replace - basicTo search and replace with a string, you can use the following command$pyreutil-fexamples/swift-s'-'-r'_'-iSearch and replace - groupTo search and replace with a regex group, you can use the following command:$pyreutil-texamples/markdown/game-theory-wiki.md-s"\[([\[]?[^\[^\]]+[\]]?)]\((http[s]?://[^\)]+)\)"-g=1Alternatively, you can use group capture syntax e.g.-r='\g<1>'or-r=\1, both of which function the same as-g=1.Search and replace - lambdaYou can also use lambda function syntax to make regex substitutes with the-lor--lambda-funcarguments as in the following example.$pyreutil-fexamples/swift-s"(_)([a-z])"-l"x.group(2).upper()"Your code should work in the following function:re.sub(search_str,  lambda x : <lambda_code> , text).Saving changesFor any modifications, only a preview is shown by default. To save the changes, you can use-ito save inplace, or-cto save the changes as a copy of the original file.When using-c, if a single file is given, a copy of the file is made in the original destination. Alternatively, if a directory is given, a copy of the original folder is made with all files copied. Note that all files are included, even files that don't have any regex matches. When used in conjunction with-dor--deep, the same is applied to all files in subdirectories.An example using-dand-cis shown below.$pyreutil-fexamples/swift-s"(_)([a-z])"-l"x.group(2).upper()"-dc