{"id":20704322,"url":"https://github.com/osch/lrexrepl","last_synced_at":"2025-12-24T06:24:15.038Z","repository":{"id":66985033,"uuid":"152294458","full_name":"osch/lrexrepl","owner":"osch","description":"Search \u0026 Replace in multiple files using regular expressions and Lua","archived":false,"fork":false,"pushed_at":"2023-11-26T15:40:22.000Z","size":15,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-17T20:13:18.168Z","etag":null,"topics":["command-line-tool","lua","pcre","regex","regex-util","regexp"],"latest_commit_sha":null,"homepage":null,"language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/osch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-09T17:40:14.000Z","updated_at":"2024-07-24T18:13:53.000Z","dependencies_parsed_at":"2023-11-26T16:42:30.081Z","dependency_job_id":null,"html_url":"https://github.com/osch/lrexrepl","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osch%2Flrexrepl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osch%2Flrexrepl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osch%2Flrexrepl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osch%2Flrexrepl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/osch","download_url":"https://codeload.github.com/osch/lrexrepl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242973963,"owners_count":20215245,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["command-line-tool","lua","pcre","regex","regex-util","regexp"],"created_at":"2024-11-17T01:11:55.774Z","updated_at":"2025-12-24T06:24:15.010Z","avatar_url":"https://github.com/osch.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lrexrepl \n[![Licence](http://img.shields.io/badge/Licence-MIT-brightgreen.svg)](LICENSE)\n[![Install](https://img.shields.io/badge/Install-LuaRocks-brightgreen.svg)](https://luarocks.org/modules/osch/lrexrepl)\n\n\u003c!-- ---------------------------------------------------------------------------------------- --\u003e\n\nCommandline tool for Search \u0026 Replace in multiple files using Regular Expressions and\nLua scripting language.\n\nThis package is also available via LuaRocks, see https://luarocks.org/modules/osch/lrexrepl.\n\nSee below for full [documentation](#documentation) .\n\n\u003c!-- ---------------------------------------------------------------------------------------- --\u003e\n\n#### Requirements\n\n   * [lrexlib-pcre]\n   * [luafilesystem]\n\n[lrexlib-pcre]:  https://luarocks.org/modules/rrt/lrexlib-pcre\n[luafilesystem]: https://luarocks.org/modules/hisham/luafilesystem\n\n\u003c!-- ---------------------------------------------------------------------------------------- --\u003e\n\n## Examples\n\nRemove tabs and spaces at end of lines in all files and subdirectories of the current \ndirectory:\n\n```bash\nlrexrepl  -p '[ \\t]*$' -r '' -R .\n```\n\nReplace all `Hello ...` with `Hello ...!` in the given files:\n\n```bash\nlrexrepl  -p '(Hello +\\w+)' -r '%1!' file1 file2\n```\n\nReplace all DOS line endings with UNIX line endings in all txt files found by \nthe find command:\n\n```bash\nfind -name \"*.txt\" | lrexrepl  -p '\\r\\n' -r '\\n'\n```\n\nAdd 100 to all numbers in the given files:\n\n```bash\nlrexrepl  -p '\\d+' -l 'tonumber(m[0])+100' file1 file2\n```\n\nCount the number of lines in all files and subdirectories of the current \ndirectory:\n\n```bash\nlrexrepl  -p '^.*$' -b 'c=0' -l 'c=c+1' -e 'printf(\"count=%d\\n\",c)' -R .\n```\n\nCount the number of newline characters in all files and subdirectories of the current \ndirectory:\n\n```bash\nlrexrepl  -p '\\n' -b 'c=0' -l 'c=c+1' -e 'printf(\"count=%d\\n\",c)' -R .\n```\n\nLua script arguments can also be given as *.lua files:\n\n```bash\necho \"c=0\" \u003e foo.lua\nlrexrepl  -p '\\n' -b 'foo.lua' -l 'c=c+1' -e 'printf(\"count=%d\\n\",c)' -R .\n```\n\n\u003c!-- ---------------------------------------------------------------------------------------- --\u003e\n\n## Documentation\n\n   * [Invocation](#invocation)\n   * [Extensions](#extensions)\n\n\u003c!-- ---------------------------------------------------------------------------------------- --\u003e\n\n### Invocation\n\n```\nUSAGE:\n    lrexrepl [OPTIONS] -p \u003cpat\u003e (-r|-l) \u003crepl\u003e [-] [--] [\u003cfile1\u003e ...]\n\n    Searches all given files and replaces all pattern matches by using a\n    replace pattern or invoking a given lua script. \n\n    Options and parameters can appear in any order in the argument list before \n    the first '--'. Every argument after '--' is considered as file name.\n    \n    If '--' is not specified and no files are given on the commandline, \n    input file names are read line by line from stdin.\n    \n    If '-' is specified input data from stdin is processed instead of file \n    content. In this case the processed data is written to stdout.\n    \n    Lua scripts can be given directly on the commandline as arguments for -l, \n    -b, -e, -f, -a. If one of these script arguments ends with '.lua' it is\n    interpreted as file name containing the lua script to be called.\n\nPARAMETERS:\n    -p \u003cpat\u003e  - search pattern: is a regular expression pattern in PCRE\n                syntax.\n\n    -r \u003crepl\u003e - replace pattern: may contain placholder %0 for referencing the\n                matched string, %n for the n-th matched group, n = 1...9.\n\n    -l \u003crepl\u003e - lua script called for each match: The script may return \n                the substituted string, or nil if no substitution should be \n                performed for this match. \n                The following variables are given: 'm' contains a table with \n                all subpatterns m[0], m[1], ... (named subpatterns are also \n                supported), variable 'f' contains current file name,\n                variable 'startPos' contains start position of the match, \n                variable 'endPos' contains end position of the match.\nOPTIONS:\n    Single letter options without arguments can be combined, e.g. -Ri is \n    equivalent to -R -i.\n    \n    -i        - ignore case\n\n    -M        - disable multi line matching, i.e. '^' matches begin of file and\n                '$' end of file. Without this option '^' matches begin of line \n                and '$' end of line.\n\n    -s        - dot matches all, i.e. also newlines.\n    \n    -R        - recurse directories (ignores hidden files, i.e. file names \n                starting with a dot character)\n\n    -b \u003clua\u003e  - lua script to be called at begin of processing\n                before any file is processed.\n\n    -e \u003clua\u003e  - lua script to be called at the end of processing\n                after all files have been processed.\n    \n    -f \u003clua\u003e  - lua script to be called for each file before the\n                file is being processed.\n\n    -a \u003clua\u003e  - lua script to be called for each file after the\n                file has been processed.\n    \n    -v        - print verbose output\n    -d        - print debug output\n    \n    -h, --help  print usage\n    --version   print version\n```\n\n\u003c!-- ---------------------------------------------------------------------------------------- --\u003e\n\n### Extensions\n\nAll scripts given as commandline parameter (using option `-l`, `-b`, `-e`, `-f`, `-a`)  can invoke\nuser supplied functions or use packages without the need for invoking `require`. For this the \npackage has to be supplied as subpackage of `lrexrepl-extension`. \n\n#### Example\n\nTake for example the following Lua file `lrexrepl-extension/foo.lua` for defining a extension\nfunction `foo()`:\n\n```lua\nreturn function(x)\n    return tonumber(x) + 100\nend\n```\n\nPlace this file somewhere in the Lua path such it could be required \nwith `require(\"lrexrepl-extension.foo\")`.\n\nThen you may simply invoke `foo()` in a lrexrepl command parameter script, e.g. use the following \ncommandline to add 100 to all numbers in the given files:\n\n```bash\nlrexrepl  -p '\\d+' -l 'foo(m[0])' file1 file2\n```\n\nUser supplied extensions `lrexrepl-extension/?.lua` have precedence over Lua standard globals\nor over functions preloaded by lrexrepl. The following functions are preloaded by lrexrepl:\n\n   * `printf()` = print(string.format(...))\n   * `format()` = string.format(...)\n   * `upper()`  = string.upper(...)\n   * `lower()`  = string.lower(...)\n   * `capitalize()`  makes first character of argument uppercase\n   * `uncapitalize()` makes first character of argument lowercase\n   \n\nEnd of document.\n\n\u003c!-- ---------------------------------------------------------------------------------------- --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fosch%2Flrexrepl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fosch%2Flrexrepl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fosch%2Flrexrepl/lists"}