Tutorial on replacing entire lines by keyword across multiple text files: updating directory lines and description lines in TXT at once


Translation:EnglishFrançaisDeutschEspañol日本語한국어,Update Time:2026-08-03 06:47:07
Content note: This article reflects the software version available when it was published. Interfaces and features may change with updates; please refer to the current software. If you find an error, please let us know.
Software featured in this articleHeSoft Doc Batch Tool
Free DownloadSoftware IntroductionUser Guide

If you need to replace old lines in batch TXT files that share the same directory lines, title lines, or configuration lines based on keywords, you can use HeSoft Doc Batch Tool to perform batch operations. Starting from the before and after effects, this article explains how to select the line replacement function in the text tool, import multiple TXT files in bulk, set precise search keywords, and enter the corresponding complete new line content, helping users quickly standardize content across multiple files.

Many office workers encounter a seemingly simple but time-consuming task when organizing text materials: a batch of TXT files all contain similar directories, appendices, descriptions, or configuration items, and now the entire lines containing certain keywords need to be uniformly changed to new text. For example, files 1.txt through 5.txt all have lines starting with "Annex A," "Annex B," "Annex C," and "Annex D," but each line is followed by an old version description. The goal now is to replace these old description lines entirely with more concise new lines, such as "Annex A - Q&A," "Annex B - Safety Attentions," etc.

If you are only processing one file, manual modification is not difficult; but when the number of files increases to dozens or hundreds, repeatedly opening, searching, modifying, and saving will take up a lot of time. Even more troublesome is that manual processing is very difficult to ensure consistency across every file, and a slight inattention could lead to missing a file or a line. This article will introduce how to use the office software " HeSoft Doc Batch Tool " to batch replace all lines containing keywords in many text files with new lines, helping you turn repetitive TXT file editing tasks into a one-time batch process.

Applicable Scenarios: Which Tasks Are Better Suited for Replacing Entire Lines by Keyword Than Normal Replacement

In text processing, "replacing keywords" and "replacing entire lines containing keywords" are two different concepts. A normal replacement usually only changes the matched words, whereas a whole-line replacement replaces the entire old content on a line with a new line of content. For directory lines, field lines, title lines, and fixed-format description lines, whole-line replacement is often more suitable.

For example, an original text has this line: "Annex A Food and drink standards, and nutrient standards for primary and secondary aged pupils - revised 2020". If you only replace "Annex A" with "Annex A - Q&A," the old description behind it remains in place, making the final content messy. However, a whole-line replacement directly transforms the entire line into "Annex A - Q&A", resulting in a cleaner outcome.

This method is suitable for the following office scenarios:

  • Batch updating appendix titles, chapter directories, and description lines in multiple txt files.
  • Batch replacing old field descriptions in text lists exported from systems.
  • Batch maintaining parameter lines containing fixed keywords in configuration files.
  • Batch cleaning up old version information in project materials, training materials, or standard documents.
  • Unifying similar content across different text files into new, standardized expressions.

Although the demonstration here uses txt plain text files, the thought process is similar to batch processing other office files: first determine the processing object, then define the rules, and finally let the software execute the repetitive actions. The value of HeSoft Doc Batch Tool lies precisely in this—it reduces repetitive labor by batch processing files, rather than requiring users to edit file by file manually.

Effect Preview: Old Line Content in TXT Files Before Processing

Before processing, there are 5 text files to be processed in the folder, named 1.txt, 2.txt, 3.txt, 4.txt, and 5.txt respectively. These files are all TXT text files and are the targets of this batch processing.

image-Replace entire lines in text files,replace lines based on keywords,batch modify TXT files,batch update text content

Opening 1.txt reveals that there is a set of "Annexes" related content at the beginning of the file. The lines highlighted by the red box start with "Annex A," "Annex B," "Annex C," and "Annex D" respectively, each followed by original English descriptions. The area pointed to by the arrows is the target region requiring batch replacement.

image-Replace entire lines in text files,replace lines based on keywords,batch modify TXT files,batch update text content

It is particularly important here to understand the meaning of "the entire line containing the keyword." Taking "Annex B The secondary school analysed meal" as an example, the keyword can be "Annex B," but what truly needs replacing is not just these characters, but this entire line. That is to say, after processing, the entire line will be changed to the new content set by the user.

Effect Preview: Old Description Lines Replaced with New Standard Lines After Processing

In the screenshot after processing, the content at the beginning of the same 1.txt file has changed. The 4 lines that originally contained old descriptions have been replaced with new standardized expressions:

  • Annex A - Q&A
  • Annex B - Safety Attentions
  • Annex C - Important Notes
  • Annex D - Other Remarks

image-Replace entire lines in text files,replace lines based on keywords,batch modify TXT files,batch update text content

Based on the results, the software only modified the lines that hit the keywords, while "Contents" and the chapter list below remain unchanged. This point is extremely important for batch processing, because most office files do not require a complete rewrite, but only need updates to content in fixed positions or with fixed characteristics.

Operation Steps: Batch Replacing Lines Containing Keywords with New Lines

The specific operation is explained below based on the software screenshots. The overall process can be understood in four steps: select the function, import files, set search and replace rules, set the save location, and start processing.

Step 1: In the Text Tool, enter "Find and Replace Complete Lines Based on Keywords"

After launching HeSoft Doc Batch Tool , first find "Text Tools" in the left navigation bar. The product name displayed in the upper left corner of the screenshot is " HeSoft Doc Batch Tool ," indicating this is an office software designed for batch processing of documents and files, not a regular notepad editor.

On the Text Tools page, find and click "Find and replace complete lines in text files based on keywords." The description for this function card states that it can batch delete or replace the entire line containing a specific keyword in text files with new text. This tutorial aims to replace with new text, so choosing this function perfectly matches the requirement.

image-Replace entire lines in text files,replace lines based on keywords,batch modify TXT files,batch update text content

After this step is completed, the software will enter the corresponding wizard page. Selecting the correct function is critical because if you choose the regular "Find and replace keywords in text," it might only process the keywords themselves, not the entire line content.

Step 2: Add Multiple TXT Files and Confirm the Pending Processing List

After entering the function page, step 1 is "Select records to process." The top right of the interface provides two main entry points: "Add Files" and "Import Files from Folder." For this example where 1.txt through 5.txt are gathered in the same folder, using "Import Files from Folder" will be more convenient; if files are scattered in different locations, you can also select them via "Add Files."

After importing, the files will be displayed in a table. The screenshot shows 5 records, all with the txt extension, with paths pointing to 1.txt, 2.txt, 3.txt, 4.txt, 5.txt in the test directory of the D drive. The table also displays information such as creation time and modification time, which is helpful for checking whether the correct versions of files have been imported.

image-Replace entire lines in text files,replace lines based on keywords,batch modify TXT files,batch update text content

The expected outcome of this step is: all text files requiring content replacement are in the list, and the total record count at the bottom matches the actual number of files. After confirming there are no errors, click "Next" at the bottom. If a file that does not need processing appears in the list, you can use the delete button in the corresponding operation column to remove it, preventing accidental processing.

Step 3: Select Exact Text Search and Enter the Keywords for Positioning

After entering step 2 "Set processing options," first set the search method. In the screenshot, "Exact Text Search" is selected. Since the target keywords in this example are very clear, namely "Annex A," "Annex B," "Annex C," and "Annex D," using exact search is easier to understand and more suitable for fixed text matching.

In the "List of keywords to search for," enter the keywords to be identified, one per line. The example input is as follows:

  • Annex A
  • Annex B
  • Annex C
  • Annex D

The software will scan the imported TXT files based on these keywords. As long as a line contains the corresponding keyword, that line becomes a candidate for replacement. There is no need to input the entire long description behind the old line here, unless you wish to limit the matching scope through longer text.

image-Replace entire lines in text files,replace lines based on keywords,batch modify TXT files,batch update text content

You can also see additional options in the interface such as "Ignore letter case" and "Match whole word, not part of a word." Although these options are not the main operational focus in the screenshot, they can be selected based on the text characteristics during actual use. If the case might be inconsistent in the files, the case matching rules should be carefully assessed; if the keyword could easily appear within longer words, attention should also be paid to whole word matching.

Step 4: Enter the New Complete Lines in the Replacement List

The "Replacement keyword list" on the right side is used to fill in the line content after processing. The 4 lines input in this example are:

  • Annex A - Q&A
  • Annex B - Safety Attentions
  • Annex C - Important Notes
  • Annex D - Other Remarks

The core of this step is to maintain correspondence between the left and right sides. The first keyword on the left is "Annex A," so the first line on the right should be filled with "Annex A - Q&A"; the second line on the left is "Annex B," so the second line on the right corresponds to "Annex B - Safety Attentions." This ensures that during batch replacement, the software can replace lines hit by different keywords with their respective correct new content.

If the replacement content corresponding to a keyword is not completely filled in, it could lead to unexpected results. Therefore, it is recommended to check line by line before proceeding to the next step. Especially when batch processing multiple files, the more accurate the initial settings are, the lower the probability of rework later.

Step 5: Continue to Set Save Location, Then Start Batch Processing

Once the keywords and replacement content are all set, click "Next" at the bottom. According to the wizard flow at the top of the page, the software will then proceed to "Set save location," followed by "Start processing." These two steps are used to confirm where the processing results are saved and formally execute the batch replacement task.

Since batch processing will affect multiple text files at once, it is recommended to check three items again before starting processing: First, whether the file list only contains the txt files to be processed; second, whether the left keywords are accurate enough; third, whether the lines on the right after replacement correspond one-to-one in order with those on the left. Start processing after confirmation.

After processing is complete, you can open one of the output files to check. Referencing the screenshot after processing, the original 4 old description lines have become the new standard lines, indicating that the batch replacement rules have taken effect. If there are multiple files, you can randomly spot-check a few to confirm the results are consistent.

Common Issues and Precautions

1. Why use whole-line replacement instead of just replacing keywords?

Because in many cases, the old content is not just the keyword itself, but the entire line where the keyword resides. Replacing only the keyword might leave the old description behind, causing a mix of old and new content. Whole-line replacement can directly overwrite the old line with a new line of content, which is more suitable for updating titles, directories, descriptions, and configuration items.

2. Is a shorter keyword always better?

No. A keyword that is too short might match lines that should not be processed. For example, writing only "Annex" might hit all appendix-related lines, making it impossible to distinguish between A, B, C, and D. It is recommended to use keywords that can accurately locate the target lines, such as "Annex A" or "Annex B."

3. Can multiple keywords correspond to different new lines?

Yes. As seen from the screenshot, both the left keyword list and the right replacement keyword list are multi-line inputs. Each keyword can correspond to a different new line of content, suitable for completing batch replacements with multiple rules at once.

4. What preparations are needed before batch processing?

It is recommended to first organize the folder to be processed, confirm the file extension is txt, and prepare a mapping table of keywords and new line content. For important files, it is best to make a backup copy first. Although batch processing is efficient, it also requires accurate rule settings.

5. If file content encoding or line break format differs, will it affect the processing?

The text files in the screenshot are shown as UTF-8 and Windows line break format. When processing text files from different sources in practice, it is advisable to spot-check a few files first to confirm the content can be opened and displayed normally. This can reduce anomalies caused by differences in file formats.

Summary: Let Office Software Batch Complete Repetitive Multi-File Modifications

Batch replacing all lines containing keywords in many text files with new lines is a typical office task that is highly repetitive and has clear rules. Manual processing wastes time and is prone to errors; using HeSoft Doc Batch Tool , you can import multiple TXT files at once through the "Find and replace complete lines in text files based on keywords" function in "Text Tools," then uniformly set keywords and replacement lines, and finally complete the content update in batch.

If you are maintaining a batch of txt text materials, configuration specifications, directory lists, or exported files, and need to change the lines containing fixed keywords to new content, you can follow the steps in this article to test with a small number of files first, then expand the processing to the entire folder. This ensures controllable results while significantly reducing repetitive labor, leveraging the efficiency advantage of office software in batch file processing.


Keyword:Replace entire lines in text files , replace lines based on keywords , batch modify TXT files , batch update text content
Creation Time:2026-08-03 06:46:50
Software featured in this articleHeSoft Doc Batch Tool
Free DownloadSoftware IntroductionUser Guide
Content note: This article reflects the software version available when it was published. Interfaces and features may change with updates; please refer to the current software. If you find an error, please let us know.