How to Delete All Matching Lines from Multiple Text Files at Once: Wildcard Regular Expression Batch Processing Method


Translation:EnglishFrançaisDeutschEspañol日本語한국어,Update Time:2026-07-04 06:36:44

Disclaimer: All images, text, and video content on the website are for reference only and may not be the latest, correct, or accurate. In case of any dispute, please refer to the actual experience effect!

When you need to delete all lines matching a certain pattern from multiple text files, manual editing is very inefficient. This article uses deleting appendix lines such as Annex A and Annex B as an example to explain how to import multiple txt files in HeSoft Doc Batch Tool , select the complete line find and replace function, use Annex [A-Z] as a wildcard regular expression matching rule, and complete batch deletion by leaving the replacement list empty, helping users quickly clean up large amounts of text data.

Many office documents, after conversion, export, or consolidation, generate a large number of TXT text files. These files often contain unnecessary lines, such as appendix descriptions, table of contents prompts, system tags, repeating headers, or log labels. Processing a single file isn't difficult, but when you face multiple text files in a folder, opening, finding, deleting, and saving each one individually becomes a typical example of inefficient, repetitive work.

The method introduced in this article uses wildcard regular expressions to batch delete all matching lines across multiple text files. The example involves deleting appendix lines like Annex A, Annex B, Annex C, and Annex D. Their common characteristic is starting with "Annex" followed by a capital letter. Therefore, the pattern Annex [A-Z] can be used to generalize this type of text, allowing office software to perform automatic batch processing.

The tool used in this article is the one shown in the screenshot: " HeSoft Doc Batch Tool ". It is a batch document processing software designed for office scenarios, suitable for centralizing repetitive file processing tasks. Following the actual screenshot order, the complete workflow from viewing the original file to completing the batch deletion is explained below.

Applicable Scenario: When you need to delete "an entire line matching a pattern"

In text processing, deleting a few fixed characters and deleting an entire line are two different requirements. For example, if a line contains "Annex A Food and drink standards - revised 2020", deleting only "Annex A" would leave the subsequent explanatory text in the file, potentially making the content incomplete. What is truly needed is deleting the entire line containing Annex A.

The "Find and replace complete lines in text files by keyword" feature in HeSoft Doc Batch Tool is designed for exactly this need. It can locate target lines based on a keyword or expression and then replace or delete the entire line.

File types and business scenarios suitable for this method include:

  • Batch cleaning of appendix lines, table of contents lines, and explanatory lines from multiple .txt files;
  • Deleting all record lines containing a specific keyword in log files;
  • Organizing system-exported text data by removing repeating headers or comments;
  • Processing large text lists, deleting lines with fixed prefixes or numbering patterns;
  • Completing batch text cleansing without writing code or running scripts.

If your files are Word documents (e.g., .docx, .doc), PDFs, or Excel spreadsheets, you should look for the corresponding tool type within the software. The screenshots in this article show the TXT file processing workflow under the Text Tools section, so the focus is on batch deleting lines from text files.

Before Processing: Multiple TXT files awaiting unified cleanup

First, let's look at the state of the files before processing. The screenshot shows 5 text files in the same folder, named 1.txt, 2.txt, 3.txt, 4.txt, and 5.txt. They are all targets for batch processing.

image-Delete lines from multiple text files,wildcard regex batch processing,batch delete matching lines,text batch processing tool

Opening one of the text files reveals a set of Annex lines in the content. The Annex A, Annex B, Annex C, and Annex D lines highlighted by the red box are the content to be deleted in this article. These lines are followed by different descriptions, indicating they are not identical fixed text.

image-Delete lines from multiple text files,wildcard regex batch processing,batch delete matching lines,text batch processing tool

Because the descriptions after each line differ, the "complete line containing the keyword" processing approach is more suitable. We only need to match the patterned part of the line, i.e., "Annex" plus a letter, and the software will delete the entire line, without needing to enter every full line into the find list.

After Processing: All lines matching the Annex rule have disappeared

After processing, the result screenshot shows that the original Annex A through Annex D lines have been deleted. The file retains the "Annexes" header at the top, and the subsequent Contents directory and numbered entries are preserved, indicating the processing target was accurate and did not delete unrelated content.

image-Delete lines from multiple text files,wildcard regex batch processing,batch delete matching lines,text batch processing tool

The advantage of this type of batch processing lies in its consistent results. As long as multiple files contain Annex lines following the same pattern, the software processes all imported files using the same rule, eliminating the need for manual judgment on a case-by-case basis. For organizing large volumes of text materials, this can significantly reduce repetitive operation time.

Operation Steps: Using HeSoft Doc Batch Tool to Complete Batch Deletion

Step 1: Open the Text Tools functional area

After opening HeSoft Doc Batch Tool , the left navigation bar provides entry points for different types of office file processing, such as Word Tools, Excel Tools, PowerPoint Tools, PDF Tools, and Text Tools. Since the sample file extension is .txt, enter "Text Tools".

In the Text Tools list, find and select "Find and replace complete lines in text files by keyword". In the screenshot, this function is the second item, with a description indicating it can batch delete entire lines containing a keyword in text files or replace them with new text.

image-Delete lines from multiple text files,wildcard regex batch processing,batch delete matching lines,text batch processing tool

Selecting this function initiates a wizard-style processing flow. The wizard guides users through importing files, setting rules, specifying a save location, and starting the process, making it suitable for office users who prefer not to write scripts.

Step 2: Add or import multiple text files

In the "Select records to process" step, all the .txt files to be processed need to be added to the list. The upper right corner of the interface has action buttons like "Add File", "Import Files from Folder", "Clear", and "More". The example has imported five files, from 1.txt to 5.txt.

image-Delete lines from multiple text files,wildcard regex batch processing,batch delete matching lines,text batch processing tool

The information displayed in the list includes sequence number, name, path, extension, creation time, and modification time. This information helps confirm the files are correct. For instance, the extension column shows .txt, and the path column shows the files are located in the D:\test\ directory. After confirming the file list has no omissions or incorrect additions, click the "Next" button at the bottom.

For batch processing tasks, checking the file list is very important because the subsequent rules will be applied to all files in the list. If irrelevant files are added to the list, they will also be processed.

Step 3: Set the search mode to "Use formula for fuzzy text search"

After entering the "Set processing options" screen, you first see the "Search mode". The screenshot shows two options: "Exact text search" and "Use formula for fuzzy text search". To match a class of text using wildcard regular expressions, select "Use formula for fuzzy text search".

image-Delete lines from multiple text files,wildcard regex batch processing,batch delete matching lines,text batch processing tool

This choice determines the flexibility of the search rule. If searching for fixed text, an exact search can be used; to match variable content like Annex A, Annex B, Annex C, a fuzzy formula search is needed.

Step 4: Enter the matching rule Annex [A-Z]

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

Annex [A-Z]

This rule matches text starting with "Annex" followed by a space and a single capital letter. The sample lines Annex A, Annex B, Annex C, and Annex D all conform to this rule. Since the function processes entire lines, lines containing this matched content will be processed as a whole.

A practical tip: Before batch processing, observe the common characteristics of the target lines. Do not rush to copy every complete line into the find list; instead, first distill the pattern. The clearer the pattern, the more concise the expression, and the higher its reuse value.

Step 5: Keep the "replacement keyword list" empty

The area on the right is the "Replacement keyword list", with a prompt stating "Leave blank to delete". Therefore, if the goal is to delete all matching lines, do not enter any replacement text on the right side. The left side handles the search, and leaving the right side blank means deletion.

If you fill in content on the right side, the software may execute replacement logic, substituting the matched lines with the text you entered. The goal in this article is to delete the Annex lines, so keeping it empty is the correct approach.

Step 6: Continue to set save location and start processing

After setting the search and delete rules, click the "Next" button at the bottom. As seen in the process bar, the next steps are "Set save location" and "Start processing". The save location determines the output directory for the processed files. It is recommended to save the output results separately from the original files to facilitate comparison of pre- and post-processing differences.

Upon entering the start processing step, the software executes the deletion rule for each file in the imported list. After processing, spot-check the output files to confirm that lines like Annex A and Annex B have been deleted, while the body text and table of contents remain.

FAQ & Important Notes

1. Is it better to write the wildcard regular expression rule as broadly as possible?

No. The broader the rule, the larger the matching scope, and the higher the risk of accidental deletion. For example, using only "Annex" might match all lines containing that word, including headers you might want to keep. Using Annex [A-Z] in this article is more targeted than just using "Annex".

2. Why wasn't the "Annexes" header deleted?

The sample expression is Annex [A-Z], requiring "Annex" followed by a space and a capital letter. Since "Annexes" does not match this rule, it was preserved. This also demonstrates that a well-designed expression can prevent the deletion of content that should not be removed.

3. Can I test with a small number of files first?

Doing so is recommended. While batch processing is efficient, incorrect rules can have a wider impact. It's wise to first import one or two sample files for testing, confirm the post-processing results meet expectations, and then import the full folder for batch processing.

4. How to verify the results after processing?

Open several output files and compare the content before and after. In the example used in this article, the pre-processing files had lines from Annex A to Annex D; after processing, these lines disappeared, while the Contents and subsequent numbered directory were retained. As long as this outcome is achieved, the rule setup is considered correct.

Summary: Let office software complete batch text cleanup

If multiple text files all contain patterned lines that need to be deleted, manual processing is not the optimal solution. Using HeSoft Doc Batch Tool , the repetitive sequence of "opening a file, finding content, deleting the entire line, and saving the file" can be consolidated into a single batch task.

The key settings in this article's example are: selecting "Find and replace complete lines in text files by keyword" in Text Tools, importing multiple .txt files, using "Use formula for fuzzy text search", entering Annex [A-Z], and leaving the replacement keyword list empty. This enables the batch deletion of all complete lines matching the Annex letter pattern.

If you are organizing a large number of TXT files, log files, or exported text, it is advisable to first analyze the common pattern of the content to be deleted, and then use wildcard regular expressions for batch processing. This can significantly reduce menial labor, improve file cleanup efficiency, and ensure consistent processing results across multiple files.


Keyword:Delete lines from multiple text files , wildcard regex batch processing , batch delete matching lines , text batch processing tool
Creation Time:2026-07-04 06:36:21

Disclaimer: All images, text, and video content on the website are for reference only and may not be the latest, correct, or accurate. In case of any dispute, please refer to the actual experience effect!

Related Articles

Don't see the feature you want?

Provide us with your feedback, and after evaluation, we will implement it for free!