{"id":28298993,"url":"https://github.com/leojimenezg/find-and-replace-txt","last_synced_at":"2025-07-22T13:07:03.961Z","repository":{"id":289764844,"uuid":"972328735","full_name":"leojimenezg/find-and-replace-txt","owner":"leojimenezg","description":"A Lua script for processing .txt files. Offers interactive options to search, replace, and count specific text occurrences within file content.","archived":false,"fork":false,"pushed_at":"2025-07-13T21:29:33.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-13T23:32:10.877Z","etag":null,"topics":["automatization","file-generation","find-and-replace","lua"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leojimenezg.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,"zenodo":null}},"created_at":"2025-04-24T22:41:18.000Z","updated_at":"2025-07-13T21:29:36.000Z","dependencies_parsed_at":"2025-07-13T23:25:38.172Z","dependency_job_id":"85d92c15-ceab-45fa-b5fb-10a4b16b64bd","html_url":"https://github.com/leojimenezg/find-and-replace-txt","commit_stats":null,"previous_names":["leojimenezg/find-and-replace-lua","leojimenezg/find-and-replace-txt-lua","leojimenezg/find-and-replace-txt"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/leojimenezg/find-and-replace-txt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leojimenezg%2Ffind-and-replace-txt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leojimenezg%2Ffind-and-replace-txt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leojimenezg%2Ffind-and-replace-txt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leojimenezg%2Ffind-and-replace-txt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leojimenezg","download_url":"https://codeload.github.com/leojimenezg/find-and-replace-txt/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leojimenezg%2Ffind-and-replace-txt/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266499337,"owners_count":23938841,"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","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["automatization","file-generation","find-and-replace","lua"],"created_at":"2025-05-23T06:15:45.087Z","updated_at":"2025-07-22T13:07:03.950Z","avatar_url":"https://github.com/leojimenezg.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Find and Replace Txt\n\nA Lua script for processing `.txt` files. Offers interactive options to search, replace, and count specific text occurrences within file content.\n\n---\n\n## Installation\n\nTo get this project up and runnig on your local machine, follow the next instructions.\n\n### Prerequisites\nBefore anything else, make sure you have installed **Lua 5.x.x** or a newer version in your system.\n\n### Steps\n1. **Clone the repository:**\nOpen your prefered terminal and clone the project to your local machine.\n    ```bash\n    git clone https://github.com/leojimenezg/find-and-replace-txt.git\n    ```\n2. **Navigate into the project directory:**\n    ```bash\n    cd find-and-replace-txt\n    ```\n3. **Run the Application: Finally, execute the main script to launch the Find and Replace Txt Program**\n    ```bash\n    lua src/main.lua\n    ```\n\n---\n\n## How Does It Work?\n\nThis script operates by reading input parameters and the text content to be processed from `data.txt`, and writing the results of replace operations to `output.txt`.\n\n### `data.txt`\nThis file serves as the primary input source. It must be structured with specific information on the first two lines, followed by the content you wish to process:\n1. **First line:** Must contain **only** the **search term** (the text you want to find).\n    * *Example:* `ipsum`\n2. **Second line:** Must contain **only** the **replacement term** (the text you want to use for replacement). This line is ignored when using the **Count all occurrences** option, but it must be there even if it is blank.\n    * *Example:* `LUA`\n3. **Rest of the file (starting from the third line):** Contains the actual **text content to be processed**. The script will read all lines from the third line onwards. There are no specific formatting limitations for this section. However, if you are working with a massive amount of text, it is strongly recommended to divide it in blocks.\n\n### `output.txt`\nThis file is used by the script to store the result of operations that involve text replacement.\n* You do **not** need to prepare this file beforehand. The script will create the `output.txt` file if it doesn't exist or **overwrite** its entire content with the new result if it already exists.\n* After a successful replace operation, the processed text will be written to `output.txt`, from where you can easily access and copy it.\n\n***Example of Replacement Output:***\n\n* *Original content (read from `data.txt`, line 3 onwards)*:\n*Lorem ipsum dolor sit amet, consectetur ipsum adipiscing elit.*\n* *Resulting content (written to `output.txt` after replacement)*:\n*Lorem LUA dolor sit amet, consectetur LUA adipiscing elit.*\n\n---\n\n## Available Options\n\nThe script presents a command-line menu with the following interactive options for processing the content from `data.txt`:\n### 1. Replace all occurrences:\n* Finds all occurrences of the **search term** (from `data.txt` line 1) within the content (from `data.txt` line 3 onwards).\n* Replaces every found occurrence with the **replacement term** (from `data.txt` line 2).\n* Writes the entire modified content to `output.txt`, **overwriting** any previous content in that file.\n\n### 2. Count all occurrences:\n* Finds all occurrences of the **search term** (from `data.txt` line 1) within the content (from `data.txt` line 3 onwards).\n* Ignores the **replacement term** (from `data.txt` line 2).\n* Counts the total number of occurrences found.\n* Does **not** modify the original content or write to `output.txt`.\n* Displays the total count directly in the terminal.\n\n### 3. Replace and Count all occurrences:\n* Performs both the replacement and counting actions.\n* Executes the replacement process as described in **Option 1** (finding and replacing all occurrences, writing modified content to `output.txt`).\n* Simultaneously, counts the total number of replacements made, as described in **Option 2**.\n* Displays the total count in the terminal after completing the replacement and file writing.\n\n### 4. Exit:\n* Terminates the script immediately. No processing or file changes are performed.\n\n---\n\n## Notes\n\n* This project is my first one to be completed in Lua, which makes it quite special to me. I certainly encountered challenges and made mistakes while writing it, but working with Lua has been a very positive experience, and it has quickly become one of my favorite programming languages.\n* I've used this script for my own personal text processing needs and found it to be reliable when the input in `data.txt` is correctly formatted as described in the **How Does It Work?** section. If you experience any issues, please double check the format of your `data.txt` file.\n* Developing this relatively small project was highly valuable and entertaining. It strongly reinforced important development principles, such as focusing on building a basic functional core first and then adding complexity, and highlighted the efficiency gained by utilizing a language's built-in features (like `string.gsub`).\n\n---\n\n## Useful Resources\n\n* **[Lua Manual](https://www.lua.org/manual/5.4/)** - The official and comprehensive reference manual for Lua 5.4.\n* **[PiL Files Chapter](https://www.lua.org/pil/21.1.html)** - A chapter from the *Programming in Lua* book covering file input and output.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleojimenezg%2Ffind-and-replace-txt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleojimenezg%2Ffind-and-replace-txt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleojimenezg%2Ffind-and-replace-txt/lists"}