Batch Replacement of Whole Lines in TXT Text: Change Specified Lines in Multiple Text Files to New Content Based on Keywords
Translation:EnglishFrançaisDeutschEspañol日本語한êµì–´ï¼ŒUpdate Time:2026-08-03 06:44:20
When multiple TXT text files contain entries with the same structure, opening each file individually to find and manually modify them is time-consuming and prone to omissions. This article describes how to use HeSoft Doc Batch Tool to search for complete lines by keywords across multiple text files, and replace the entire matched line with new content. In the example, lines containing Annex A, Annex B, Annex C, and Annex D in 1.txt through 5.txt are uniformly changed to new explanatory text, suitable for batch-revising directories, configurations, logs, inventories, and other plain text content.
In daily office work and material maintenance, many teams encounter this issue: a folder contains a large number of TXT text files, each containing content with similar formats, such as directory items, description items, configuration items, list items, or fixed labels. Now, entire lines containing certain keywords need to be uniformly replaced with new text. If you open 1.txt, 2.txt, 3.txt, 4.txt, 5.txt one by one to search, copy, and paste, it is not only inefficient but also prone to issues like missing changes in some files, incomplete line replacements, or residual old content.
This document addresses the requirement to "batch replace all lines containing keywords with new lines in many text files." The example uses the office software " HeSoft Doc Batch Tool ," which is positioned as a batch processing tool for documents, text, spreadsheets, PDFs, and other files. Its core value is reducing repetitive labor, consolidating file processing actions that need manual repetition into a single workflow. Below, we will combine screenshots to explain the state before processing, the result achieved after processing, and how to perform batch replacement in the software.
Applicable Scenarios: Which Text Files Are Suitable for Batch Replacing Entire Lines by Keyword
Replacing entire lines by keyword is not simply replacing one word with another; rather, if a line contains a specified keyword, the entire line is replaced with new, complete text. For example, if an original line is a long content like "Annex A Food and drink standards...", once it matches "Annex A", the entire line is changed to "Annex A - Q&A". This method is particularly suitable for processing structured or semi-structured TXT files.
Common scenarios include: batch modifying directory titles in multiple TXT documentation files; batch updating specified parameter lines in configuration files; batch cleaning lines containing certain identifiers in log files; batch replacing category names in exported lists; batch changing fixed entries from old version templates to new version entries. For tasks with substantial content, a large number of files, and clear repetitive rules, using office software for batch processing is more reliable than manual editing.
It is important to note that the examples in this document process plain text files, specifically files with the .txt extension. If you usually work with Word documents, you might focus on batch find and replace for formats like doc, docx; for spreadsheet content, Excel-related batch processing capabilities might be needed. The focus here is the batch replacement of "entire lines containing keywords" in TXT text files.
Result Preview: Multiple TXT Files Requiring Unified Modification Before Processing
From the screenshot of files before processing, you can see there are multiple text files in the folder; the example includes 1.txt, 2.txt, 3.txt, 4.txt, 5.txt. When the number of such files is small, it can be managed manually, but as soon as it scales to dozens or hundreds of files, manually opening and modifying each one becomes very inefficient.

Opening 1.txt, you can see multiple lines starting with "Annex" at the top of the file. The red box highlights the lines needing processing: the lines containing Annex A, Annex B, Annex C, and Annex D. They do not just contain the keyword itself; the keyword is followed by different descriptive text. For example, "Annex A" is followed by a longer English description. If it were a simple keyword replacement, the old long description might remain; however, the requirement here is to replace these entire matched lines with new standard lines.

Result After Processing: Lines Containing Keywords Are Replaced with New Complete Lines
After processing is complete, upon checking the same text file, the content in the red box has become the new lines: Annex A - Q&A, Annex B - Safety Attentions, Annex C - Important Notes, Annex D - Other Remarks. You can see that the old descriptions following the keywords have been completely replaced, with no old content remaining.

This is precisely the value of "Find by keyword and replace complete lines in text files": users only need to maintain a keyword list and a list of replacement new lines, and the software can execute the same rules in batch across multiple text files. For office scenarios like template revision, material standardization, and batch text cleaning, this method significantly reduces repetitive operations.
Operation Step 1: Enter Text Tools and Select the Feature to Replace Complete Lines by Keyword
After opening HeSoft Doc Batch Tool , select "Text Tools" from the function category on the left. On the Text Tools page, you can see multiple batch processing functions related to text. The one to use this time is "Find and replace complete lines in text files based on keywords." In the screenshot, this function is the 2nd item in the Text Tools list, and the description also indicates it can batch delete or replace entire lines containing a certain keyword in text files with new text.

The purpose of selecting this function is to have the software process content in units of "lines," rather than just replacing a single word or phrase. That is, when the software finds the keyword you entered in a line, it treats that entire line as the processing object and replaces it based on the new content you set. This prevents old descriptions, parameters, or descriptions from remaining in the original line.
Operation Step 2: Add the TXT Text Files to Be Batch Processed
After entering the function, the page title at the top displays the current function name "Find and replace complete lines in text files based on keywords," with process steps shown below. The first step is "Select records to process." On this page, you can add specified TXT files to the list via "Add Files," or import text files from a folder in bulk using "Import Files from Folder." In the screenshot, files 1.txt through 5.txt have been added, totaling 5 records.

The file list displays information such as serial number, name, path, extension, creation time, and modification time. Users can verify that the correct files are selected through these fields. For example, the file paths in the example are D:\test\1.txt, D:\test\2.txt, etc., with the extension txt. There is also an operation column on the right to remove records that do not need processing. The summary area at the bottom of the list shows "Record Count: 5," indicating that 5 text files will be batch processed.
The expected result of this step is: all TXT files needing processing have appeared in the list, and the number of files matches the actual requirement. After confirming there are no errors, click "Next" at the bottom of the page to proceed to the processing options setup.
Operation Step 3: Set Search Method, Keyword List, and Replacement New Lines
The second step is "Set processing options." In the screenshot, you can see the search method selected is "Exact Text Search." This means the software will match based on the entered text keyword. The interface also provides the option "Use Formula for Fuzzy Text Search," but in this case, the keywords are very clear, so using exact search is more intuitive and better suited for beginners.

In the "Keyword list to find," enter one keyword per line. In the example, Annex A, Annex B, Annex C, Annex D are entered sequentially. These correspond to the beginning parts of the lines needing replacement in the pre-processing text. Because these keywords can uniquely locate the lines to be replaced, the software can find the complete lines containing them accordingly.
On the right is the "Replaced keyword list." Here, you need to enter the new line content after replacement, also one rule per line. The example is set to: Annex A - Q&A, Annex B - Safety Attentions, Annex C - Important Notes, Annex D - Other Remarks. According to the screenshot prompt, "leave blank to delete," so if a right-side entry is empty, it might result in deleting the corresponding matched line; since this example is a replacement, a new complete line is filled in for each entry.
Pay special attention to the correspondence between the left and right sides when setting up. The first line on the left, Annex A, corresponds to the first line on the right, Annex A - Q&A; the second line on the left, Annex B, corresponds to the second line on the right, Annex B - Safety Attentions. Maintaining consistent order ensures each keyword is replaced with the correct new content.
Operation Step 4: Set Save Location and Start Batch Processing
After confirming the processing options, click "Next" to enter "Set save location." Although the screenshot doesn't show the specific options on the save location page, the progress bar clearly shows the third step is "Set save location" and the fourth step is "Start processing." The purpose of this step is to decide where to save the processed files, preventing users from being unable to find the result files and avoiding accidental overwriting of content that shouldn't be overwritten.
In practical office processing, it is recommended to first use a separate output directory to save the processing results, such as creating a new "Replaced Texts" folder. This allows for separate management of original and processed files, facilitating verification. Once the results are confirmed to be completely correct, you can decide whether to replace the original files or archive the old version according to your company's internal process.
After setting the save location, proceed to the "Start processing" step and execute the batch processing according to the interface prompts. The software will scan the contents of the TXT files one by one based on the previously imported file list, find lines containing the keywords, and replace them with the new lines set on the right. Once processing is complete, open the resulting files to check.
Frequently Asked Questions and Notes
1. Why use "Replace complete line" instead of regular find and replace? Regular find and replace usually only changes one word to another. If there is much old description following the original line, old content might still exist. Replacing the complete line replaces the entire matched line with new text, making it more suitable for revising directory items, configuration items, title lines, and similar scenarios.
2. Should the keyword be complete or just a part? It is recommended to write enough to uniquely identify the target line. For instance, "Annex A" can locate the target line in the example; writing just "Annex" might match all Annex-related lines, causing the replacement scope to be too broad.
3. Can the order of the left and right lists be disrupted? It is not recommended. In the example, the keyword line number on the left corresponds to the new content line number on the right. If the order is wrong, it might cause Annex A to be replaced with the description for Annex B.
4. Is backup needed before replacement? It is recommended to keep the original files or output the processing results to a new folder. Batch processing is highly efficient, but once a rule is set incorrectly, it can quickly affect multiple files. Backing up before batch processing is a more secure office habit.
5. Is this suitable for processing doc, docx, or Excel files? The examples in this document are for TXT plain text files. Word's doc, docx, or Excel spreadsheets have different file structures and generally require the use of corresponding Word tools or Excel tools for processing.
Summary: Turn Repetitive Text Modifications into One-Time Batch Processing with Office Software
Batch replacing specified entire lines in multiple TXT text files essentially tackles the problem of repetitive labor. HeSoft Doc Batch Tool , through its "Find and replace complete lines in text files based on keywords" function, consolidates repetitive actions like "open file, find keyword, select entire line, input new content, save file" into one workflow. For dozens or even more text files, you only need to import the files first, then set the keywords and new line content for unified processing.
If you frequently need to maintain text templates, configuration lists, material directories, or batch-exported txt files, it is recommended to organize such rules into clear keyword lists and then use a batch processing tool for execution. This not only saves a significant amount of manual editing time but also reduces the risk of missed or erroneous changes, making daily office file processing more stable and efficient.
Keyword:Batch TXT text replacement for entire lines , batch replacement of specified lines in text files , replace entire lines by keywords