How to replace entire lines in multiple TXT files by keywords, batch update directories and description lines
Translation:EnglishFrançaisDeutschEspañol日本語한êµì–´ï¼ŒUpdate Time:2026-08-03 06:44:38
If multiple TXT files share the same directory lines or description lines, manually modifying them one by one is both slow and error-prone. This article uses the update of directory content from Annex A to Annex D as an example to explain how to use HeSoft Doc Batch Tool to batch import TXT files, match target lines through a keyword list, and then replace old lines with new full-line content. The article includes before-and-after effects, detailed operation steps, and notes, making it suitable for office users who need to batch maintain text templates, instruction documents, and list files.
Many office documents are not necessarily complex Word, Excel, or PDF files; they can also just be a large number of TXT text files. TXT files seem simple, but when the number of files increases, the maintenance cost is not low. For example, a project data package might contain dozens of text instruction files, each with the same directory entries at the top; or multiple TXT lists exported from a system might all have fixed category lines, title lines, and parameter lines. When a rule changes one day, and you need to uniformly replace entire lines containing specified keywords with a new description, opening and modifying files one by one becomes very inefficient.
This article introduces a more suitable approach for batch office work: using HeSoft Doc Batch Tool to search for complete lines by keyword in multiple TXT files and replace the entire matched line with new content. This way, you can not only replace the words "Annex A" but also change the entire old description line. For scenarios like batch updating directories, batch revising instruction lines, and batch standardizing text file content, this method is more accurate than manual search and replace.
Applicable Scenarios: Batch Updating TXT Directories, Titles, Parameters, and Fixed Notes
"Replace entire line by keyword" is suitable for text content that contains clear identifiers within a line. For example, one line starts with "Annex A" followed by a long description; another line starts with "Annex B" followed by a different description. You don't just want to change the characters "Annex A" or "Annex B," but rather replace the entire line with a new standard expression.
In practical work, this requirement is very common. Examples include: old chapter names in product instruction files need to be uniformly adjusted; appendix names in training materials need to be replaced with new classifications; lines containing a specific parameter name in system configuration files need updating; lines containing a certain type of key identifier in log or report text need to be replaced or cleaned up; and TXT templates in multiple project folders need to be uniformly upgraded. As long as the target line can be identified by a keyword, this method can be considered for batch processing.
Compared with ordinary text editors, the batch processing capability of office software is more suitable for multi-file tasks. HeSoft Doc Batch Tool provides a process-oriented operation: first select files, then set rules, then set the save location, and finally start processing. Users do not need to repeatedly switch between multiple windows, nor do they need to remember whether each file has been modified.
Effect Preview: Multiple TXT Files Awaiting Unified Modification Before Processing
As seen in the screenshot, there are 5 TXT text files in the current folder, named 1.txt, 2.txt, 3.txt, 4.txt, and 5.txt respectively. These are the objects of this batch processing. Although the example only has 5 files, the same idea applies to many more text files. The more files there are, the more obvious the efficiency improvement brought by batch processing.

Opening the pre-processed 1.txt, you can see an "Annexes" area at the front of the file, listing lines for Annex A, Annex B, Annex C, Annex D, etc. The content in the red box is the target line that needs to be batch-replaced this time. The common characteristic of these lines is that they all contain clear keywords, and the keywords are followed by old version description text.

If operating manually, a user would need to find the line where Annex A is located in every TXT file, delete the old description, type the new description; then find Annex B, Annex C, Annex D, and repeat the same action. Even if only 4 lines are changed per file, 5 files would require 20 changes; if there were 100 files, it could reach 400 changes. Manual operation is not only time-consuming but also prone to issues like missing a spot, changing a line incorrectly, or format inconsistency.
Post-Processing Effect: Old Descriptions Replaced by New Standard Lines
After processing is complete, open the text file again, and you can see that the original long descriptions have been replaced with new short descriptions. Annex A becomes "Annex A - Q&A", Annex B becomes "Annex B - Safety Attentions", Annex C becomes "Annex C - Important Notes", and Annex D becomes "Annex D - Other Remarks". The red box area shows the result after replacement.

From the results, it can be seen that this replacement is not merely inserting new words but updating the entire line containing the keyword to a new complete line. Old content like "Food and drink standards..." is no longer retained. This processing method is very suitable for batch upgrading old documents to a new version standard and for unifying similar text across different files into a consistent expression.
Operation Step 1: Open the Corresponding Function in the Text Tool
After launching HeSoft Doc Batch Tool , the left navigation bar contains multiple tool categories, such as Word Tools, Excel Tools, PowerPoint Tools, PDF Tools, Text Tools, etc. Since the processing object this time is TXT text files, select "Text Tools" on the left. In the function list of Text Tools, find "Find and replace complete lines in text files based on keywords".

The red arrow in the screenshot points to the function used this time. The page description mentions that it can batch delete or replace entire lines containing a specific keyword in text files with new text. This article uses the replacement scenario, which means replacing the matched line with a new standard line. After clicking this function, you enter the batch processing workflow.
Operation Step 2: Import the List of Text Files to Process
After entering the function page, the first step is "Select records to process". On the top right of the page, you can see operations like "Add Files", "Import Files from Folder", "Clear", and "More". For a small number of files, you can use "Add Files"; if the files are all concentrated in the same folder, using "Import Files from Folder" is more convenient.

In the example, 5 TXT files have been imported. The list displays information such as file name, path, extension, creation time, and modification time, facilitating user verification. For instance, you can confirm that the extensions are all txt and the paths are all under the D:\test directory. If a file does not belong to this task, you can delete the record via the operation column; if there is an import error, you can also use "Clear" to re-add.
The key to this step is ensuring the accuracy of the processing scope. The efficiency of batch tools is high, but it also means the rules will be applied to all files in the list simultaneously. Therefore, before proceeding to the next step, you should check the record count and file paths to confirm there are no excess, missing, or incorrectly selected files. After confirmation, click "Next" at the bottom.
Operation Step 3: Choose Exact Text Search and Fill in Corresponding Rules
After entering "Set Processing Options", first set the search method. In the screenshot, "Exact Text Search" is selected. For clear, fixed keywords like Annex A and Annex B, exact search is easier to understand and more convenient for checking results. Additional options like "Ignore case of letters" and "Match whole word instead of part of word" can also be seen in the interface; users can decide whether to check them based on their text characteristics.

Next, fill in the keywords to match in the "List of keywords to search" on the left. The example has 4 entries: Annex A, Annex B, Annex C, Annex D. Each on a new line. The software will search for lines containing these keywords in the text files; as long as an entire line contains the corresponding keyword, it will be processed according to the settings on the right.
The "Replacement keyword list" on the right is used to fill in the new content. Each line here must correspond one-to-one with the keywords on the left. The example settings are: Annex A - Q&A, Annex B - Safety Attentions, Annex C - Important Notes, Annex D - Other Remarks. Once set, the software will replace the entire line containing Annex A with "Annex A - Q&A", the entire line containing Annex B with "Annex B - Safety Attentions", and so on.
When filling in rules, it is recommended to first confirm the uniqueness of the keywords in a sample text. If a keyword appears in multiple different types of lines, it may cause lines that shouldn't be replaced to be processed. For example, simply entering "Annex" might match all Annex-related lines without distinguishing A, B, C, D. Therefore, keywords should be as specific as possible.
Operation Step 4: Set Save Location and Execute Processing
After setting the rules, click "Next" to enter "Set Save Location". Although the screenshot does not show the specific page for the third step, this step is clearly present in the workflow. The setting of the save location is very important because it relates to how the processing results are managed. For executing a batch of rules for the first time, it is recommended to save the results to a new directory for easy comparison with the original files.
After completing the save location setting, continue to "Start Processing". The software will process the TXT files one by one according to the file list and complete the batch update based on the set keywords and replacement lines. After processing, you can open one of the result files to check the red box area and confirm whether the replacement meets expectations; you can also spot-check multiple files to ensure the rules are correctly applied across different files.
Frequently Asked Questions and Notes
1. Does the replacement content need to include the original keyword? Not mandatory, but it is generally recommended to retain an identifiable keyword. For example, replacing Annex A with Annex A - Q&A keeps the structure clear. If completely replacing with another expression, you should also confirm that it won't cause confusion during later review.
2. Can the replacement list on the right be left blank? The prompt in the screenshot says "leaving blank means deletion". If your goal is to delete entire lines containing the keyword, you can leave it blank; if the goal is replacement, you should fill in the new complete line to avoid accidentally deleting content.
3. Will file encoding affect the results? The bottom of the sample text editor shows UTF-8. Before actual processing, it is advisable to understand the original file encoding, especially for txt files containing Chinese, special symbols, or multilingual content. After processing, a spot check should be performed to see if the display is normal.
4. Can more files be processed? The advantage of batch processing tools lies in multi-file tasks. As long as files are correctly imported into the list, they can be processed according to the same rules. The more files there are, the more the value of reducing repetitive labor is reflected.
5. What is the difference compared to batch replacement in Word docx? TXT is plain text, so line-by-line processing is more direct; Word doc and docx files contain structures like styles, paragraphs, and tables, usually requiring specialized Word tools for processing. Do not mix rules for different formats.
Summary: Turning Multi-File Manual Modifications into Reusable Batch Rules
Replacing entire lines in multiple TXT files by keyword essentially transforms repetitive manual editing actions into reusable batch rules. Through HeSoft Doc Batch Tool , users only need to accomplish four things: select the function, import files, fill in keywords and new lines, and set the save location and start processing. Compared to opening files one by one to modify, this method is faster, more consistent, and easier to check.
If you are maintaining a large number of text instructions, directory files, configuration texts, or export lists, it is recommended to first sort out the keywords that need to be searched and the corresponding new line content, and then use a batch processing tool to complete the unified replacement. This not only saves office time but also reduces the probability of human omission, making text file maintenance work more standardized.
Keyword:Replace entire lines in multiple TXT files , batch modify TXT by keywords , batch update directories in text files