How to batch change lines containing years in multiple text files to specified content? Wildcard entire line replacement tutorial


Translation:EnglishFrançaisDeutschEspañol日本語한국어,Update Time:2026-08-03 06:51:00
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

This article uses the example of "how to batch replace entire lines containing years or keywords in multiple TXT text files" to explain the method of using HeSoft Doc Batch Tool to complete batch text maintenance. Through the entire-line search and replace function in the text tool, users can import multiple txt files, select formula fuzzy search, enter a regex-like \d{4} to match four-digit years, and then uniformly replace the matched entire lines with the specified new text. It is suitable for batch office scenarios such as data directories, logs, configuration files, and inventory texts.

Many office documents are not necessarily Word files; they could also be a large number of TXT text files: system-exported lists, project directories, descriptive text, configuration files, log snippets, data processing results, etc. These files appear simple in format, but once the quantity increases, batch modifications become very troublesome.

For example, a folder contains 5, 50, or even more TXT files, and each file has a line containing the old description with the year "2020". Now, this needs to be uniformly changed to the new line "Annex A - Q&A". If you use a regular text editor to open files one by one, search for the year, delete the old line, and type the new line, the process is highly repetitive, and it's easy to miss a file if you're not careful.

A more efficient approach is to use software designed for batch office processing. This article uses " HeSoft Doc Batch Tool " as an example to demonstrate how to use wildcard/regex-like methods to batch-locate lines containing keywords in multiple text files and replace the entire line with specified content. After reading this article, you can master a batch whole-line replacement method applicable to txt text files to reduce repetitive work and improve file maintenance efficiency.

Applicable Scenarios: Why Replace Entire Lines Based on Keywords

In standard find-and-replace, many people are accustomed to entering a keyword and then replacing that keyword with another word. However, in actual work, a common requirement is not "replacing a specific word," but rather "if this line contains a certain word, change the entire line."

Typical Requirements Suitable for Whole-Line Replacement

The first type is year updates. For example, text containing old version descriptions like "revised 2020" or "updated 2021," where you want the entire line replaced with a new standard description.

The second type is numbered text. For example, a line containing four-digit numbers, six-digit numbers, order numbers, work order numbers, or project numbers—as long as these characteristics are matched, the line is replaced with unified new content.

The third type is directory and list maintenance. In directory structures like Annex, Chapter, Section, Contents, certain entries need unified renaming. Replacing only partial text might leave behind old descriptions; replacing the entire line is cleaner.

The fourth type is configuration file or log file cleanup. Certain lines containing old paths, old parameters, or old switches need batch rewriting or deletion. Here, using keyword hits for entire lines is more efficient than manual filtering.

Situations Unsuitable for This Method

If your goal is only to replace a specific word in a line with another word while keeping the rest of the line's content, the method described in this article may not be the most suitable, as it replaces the complete line. For example, if you only want to change "2020" to "2026" while keeping "Annex A - Food and drink standards - revised", you should use a standard keyword replacement function, not the whole-line replacement function.

Additionally, the example in this article processes TXT plain text files. If you are processing Word documents, such as .doc or .docx, or file formats like PDF or Excel spreadsheets, you should use corresponding Word tools, PDF tools, or other specialized functions.

Effect Preview: From Multiple TXT Files to Uniform Replacement Results

The processing target for this example is multiple TXT files within a folder. As seen in the screenshot, the files include 1.txt, 2.txt, 3.txt, 4.txt, and 5.txt. Our goal is to uniformly apply the same rule to these files, not just modify a single file.

image-Batch replacement for multiple text files,including line replacement with keywords and wildcard-based full-line replacement in TXT files

Before Processing: Target Line Contains a Four-Digit Year

After opening 1.txt, you can see a line in the text content:

Annex A - Food and drink standards - revised 2020

The end of this line contains the four-digit number "2020". In this tutorial, we use \d{4} as the search rule to match consecutive four-digit numbers. Any line containing such content will be identified as a target line needing processing.

image-Batch replacement for multiple text files,including line replacement with keywords and wildcard-based full-line replacement in TXT files

It's important to emphasize that the goal here is not to replace "2020" with another year, but to replace the entire line containing "2020" with a new line of text. This is the key difference of the "Find and replace complete lines in text files based on keywords" function.

After Processing: The Hit Complete Line Becomes the Specified New Content

After processing is complete, upon checking the text file again, you can see the original long line has become:

Annex A - Q&A

image-Batch replacement for multiple text files,including line replacement with keywords and wildcard-based full-line replacement in TXT files

From the post-processing screenshot, it's clear that the third line has been replaced, while other directory lines and content lines remain unchanged. This indicates that the rule only acts on hit lines, suitable for performing uniform, controlled text maintenance across a large number of files.

Operation Steps: Batch Replace Lines Containing Keywords with New Lines

The following combines software interface screenshots to explain how to operate according to the actual process. Careful verification is recommended at each step, especially for the search rule and replacement content, because batch tools are highly efficient, and correct rule settings are essential for expected results.

Step 1: Find the Whole-Line Replacement Function in Text Tools

After launching " HeSoft Doc Batch Tool ", select "Text Tools" on the left side. In the list of text tools, find item 2, "Find and replace complete lines in text files based on keywords". The red prompt at the top of the interface also explains the function's purpose: batch delete or replace entire lines containing a specific keyword in text files with new text.

image-Batch replacement for multiple text files,including line replacement with keywords and wildcard-based full-line replacement in TXT files

The purpose of this step is to choose the correct tool entry. The text tools might also include functions like "Find and replace keywords in text," "Delete blank lines in text," "Text to Word," "Text to PDF," etc. However, this example deals with "complete lines containing keywords," so the current whole-line replacement function should be selected.

Step 2: Import Multiple Text Files to Process

After entering the function page, the first step is "Select records to process". On the top right, you can see operation buttons like "Add File," "Import Files from Folder," "Clear," and "More". For a small number of files, you can use "Add File"; if multiple TXT files are in the same folder, "Import Files from Folder" is more suitable.

image-Batch replacement for multiple text files,including line replacement with keywords and wildcard-based full-line replacement in TXT files

The screenshot shows that 5 text files have been imported, named 1.txt to 5.txt, with the .txt extension. The table lists information such as path, creation time, and modification time, with the bottom showing a record count of 5. After confirming the file list is correct, click "Next" at the bottom.

The expected result of this step is: all TXT files to be processed are added to the task list without any omissions or incorrectly added files. Confirming the files before batch processing is very important, as subsequent rules will be applied to all files in the list.

Step 3: Set Search Mode to Formula Fuzzy Search

Entering the second step, "Set processing options," first look at "Search mode". The interface provides two options: "Precise text search" and "Use formula for fuzzy text search". This example requires using \d{4} to match four-digit numbers, so select "Use formula for fuzzy text search".

image-Batch replacement for multiple text files,including line replacement with keywords and wildcard-based full-line replacement in TXT files

If you only search for fixed text, such as "Annex A", using precise search is also viable. But if you want to match content with patterns like years or numbers that are similar but not identical, you need to use formula fuzzy search. It allows for more flexible search conditions, similar to using regular expressions or wildcards.

Step 4: Enter Rules in the Keyword List to Find

In the left "Keyword list to find," enter:

\d{4}

Here, \d{4} is used to match consecutive four-digit numbers. The "2020" in the example text exactly matches this rule, so the entire line containing "2020" will be identified.

In your actual text, if the years might differ, such as 2019, 2021, 2024, as long as they are consecutive four-digit numbers, they will also be matched by this rule. For this reason, when using rules, confirm that other lines in the file that shouldn't be replaced do not also contain four-digit numbers. If such a risk exists, the rule needs to be designed more precisely.

Step 5: Fill in the Replacement Whole-Line Content

In the right "Replacement keyword list," enter:

Annex A - Q&A

This content will be the new line after replacement. During processing, the software will replace the entire line hit by the left rule with the right content. That is, the original "Annex A - Food and drink standards - revised 2020" will not just have its ending year changed, but the entire line will become "Annex A - Q&A".

The interface also prompts "Leave blank to delete". Therefore, if you just want to delete the lines containing keywords, you can leave the replacement content blank; but for the requirement in this article to replace with new text, be sure to fill in the complete new line content.

Step 6: Continue Setting Save Location and Start Batch Processing

After setting the rules, click "Next". According to the interface flow, there are two subsequent steps: "Set save location" and "Start processing". Choosing the save location carefully is recommended based on the importance of the files: for formal documents, it is advisable to save to a new output directory first and replace the original files after verification; for test files, you can handle it according to the actual situation.

After entering "Start processing," wait for the software to complete the batch task. Once finished, open the output files for spot-checking, confirming that the target lines containing four-digit numbers have been replaced with "Annex A - Q&A", and that there are no other unexpected changes.

Common Problems and Precautions

1. Why use formula fuzzy search instead of precise search?

Because the search condition in this example is \d{4}, which is not ordinary text but a rule for matching four-digit numbers. If precise search were selected, it might search for the literal string "\d{4}" itself, failing to match "2020". Selecting "Use formula for fuzzy text search" aligns with the purpose of using wildcard/regex-like rule searches.

2. Could \d{4} match lines that shouldn't be replaced?

It's possible. Any line containing consecutive four-digit numbers could be hit. If the file has other years, numbers, or codes, they might also trigger replacements. Therefore, before formal batch processing, it's recommended to test with a small number of files first to confirm the rule only hits the target lines.

3. Can the replacement content be left blank?

From the interface prompt, leaving the replacement keyword list blank means deletion. If your goal is to delete the entire lines containing keywords, you can leave it blank; if you intend to replace them with new lines, do not leave it blank, otherwise the target lines might be deleted.

4. Will lines not matching the keywords be affected?

According to the processing logic of this function, only complete lines containing the search keyword or matching the rule will be replaced. The post-processing example shows that un-hit lines, like the directory lines for Annex B, Annex C, and Contents, remain unchanged. The premise, however, is that the rule settings are accurate.

5. Can it process all text files in an entire folder?

You can batch import using "Import Files from Folder". However, after importing, you should still check the file names and extensions in the list to confirm they are all the TXT files you need to process. If the folder contains irrelevant text, you should filter them out or remove them from the list first.

6. Is a backup necessary before processing?

Backup is strongly recommended. The value of batch processing files lies in reducing repetitive operations, but if rules are set incorrectly, it can also quickly affect multiple files. The safest practice is to first copy the original folder, or output to a new directory in the save location, and only apply to formal documents after confirming the results are satisfactory.

Efficiency Value: From Individual Modification to One-Time Batch Completion

When manually modifying multiple text files, the steps usually include opening the file, finding the keyword, selecting the whole line, deleting the old content, entering new content, saving, and closing, then repeating for the next file. The more files there are, the more obvious the repetitive labor, and the higher the chance of missing changes and accidental saves.

Using HeSoft Doc Batch Tool , these repetitive actions can be transformed into a single batch task: first import files, then set search rules and replacement content, and finally output the results uniformly. For office workers who frequently need to process TXT files, logs, directory lists, and configuration texts, this method can significantly reduce processing time and improve result consistency.

Summary: Precisely Replace Entire Lines Containing Keywords Using Wildcard Rules

This article demonstrated how to batch replace whole lines containing four-digit year numbers in multiple TXT text files with specified content. The core steps include: entering Text Tools, selecting "Find and replace complete lines in text files based on keywords"; importing multiple txt files; selecting "Use formula for fuzzy text search"; entering \d{4} as the search rule; filling in "Annex A - Q&A" in the replacement keyword list; and finally setting the save location and starting the process.

This method is particularly suitable for dealing with text lines containing keywords with fixed patterns, such as years, numbers, version numbers, directory entries, etc. Compared to manually modifying files one by one, batch whole-line replacement can significantly reduce repetitive work, making text file maintenance more efficient and uniform. It is recommended to verify the rules with sample files before formally processing a large number of files, only applying them in batch once the results meet expectations.


Keyword:Batch replacement for multiple text files , including line replacement with keywords and wildcard-based full-line replacement in TXT files
Creation Time:2026-08-03 06:50:44
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.