How to batch delete specified entire lines in multiple TXT text files using wildcard regular expressions


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

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!

If many TXT text files contain directory lines like Annex A, Annex B, opening them one by one to delete them is very time-consuming and prone to omission. This article uses HeSoft Doc Batch Tool as an example to demonstrate how to use the "Find and Replace Complete Lines in Text Files by Keywords" feature, utilizing wildcard characters or regular expressions to match multiple types of content at once and batch-delete the matched entire lines, making it suitable for processing a large number of TXT texts, logs, lists, and exported materials.

When organizing a large number of TXT text files, a repetitive task often arises: each file contains a few lines of unwanted content, such as descriptive lines like Annex A, Annex B, Annex C, and Annex D preceding a table of contents. If there's only one file, you can simply open it in Notepad++ or Notepad and delete them manually. But when the number of files grows to dozens or hundreds, searching, selecting, deleting, and saving for each one is not only time-consuming but also makes it easy to miss certain files.

The problem this article addresses is clear: use the batch text processing capabilities in office software to match target lines across multiple text files simultaneously using wildcard regular expressions and delete the entire line containing these keywords. The software used in the example is shown in the top-left corner of the screenshot: " HeSoft Doc Batch Tool ". It is positioned as an office software for batch document processing, and its core value lies in reducing repetitive operations, unifying processing rules, and improving file organization efficiency.

Below, using before-and-after results and operational screenshots, we will fully explain how to batch delete specific entire lines from multiple .txt text files. Although the example files are txt, the same approach is suitable for scenarios involving plain text documents, log files, export lists, and other materials needing batch cleanup based on text content.

Applicable Scenarios: Which Text Files Are Suitable for Batch Line Deletion Using Wildcard Regular Expressions

This method is particularly suitable for text cleanup tasks that have "clear rules, a large number of files, and similar content structures." For example, if multiple TXT files all contain the same types of numbered lines, chapter lines, header lines, appendix lines, or marker lines, manual deletion would involve performing the same action repeatedly. In such cases, wildcards or regular expressions can be used for unified matching.

Taking the screenshots in this article as an example, the folder contains five text files: 1.txt, 2.txt, 3.txt, 4.txt, and 5.txt. Each file likely contains lines like Annex A, Annex B, Annex C, and Annex D. Their common feature is that they all start with "Annex" followed by a capital letter. Using an expression like Annex [A-Z] allows you to uniformly match content from Annex A to Annex Z.

Common scenarios suitable for this function include:

  • Batch deleting a certain type of table-of-contents, appendix, or explanatory line from TXT files;
  • Batch cleaning entire lines in log files that contain a specific identifier;
  • Batch deleting lines with fixed prefixes, such as numbers, comments, or tags, from exported text;
  • Batch replacing or deleting entire lines of content that follow a specific pattern across multiple text files;
  • Performing unified cleaning on a large number of text documents without opening each file individually.

The key point here is not just deleting a few specific characters but deleting the "complete line" that contains the matching keyword. This is very important for cleaning tables of contents, records, and list items, because deleting only the keyword can leave behind incomplete text, whereas deleting the entire line makes the file structure cleaner.

Effect Preview: Lines Needing Deletion in Multiple TXT Files Before Processing

From the file list before processing, the example folder contains multiple TXT text files, named sequentially from 1.txt to 5.txt. This indicates the operation is not for a single file but applies the same set of rules to a batch of text files.

image-Batch delete text lines,TXT batch processing,wildcard regular expression delete lines,text file batch replacement

Upon opening 1.txt, you can see the file has the title "Annexes" at the top, followed by the four consecutive lines Annex A, Annex B, Annex C, and Annex D. These lines are followed by different descriptive texts, such as "Food and drink standards" and "The secondary school analysed meal". The content marked by the red box and arrows is the target for this batch deletion exercise.

image-Batch delete text lines,TXT batch processing,wildcard regular expression delete lines,text file batch replacement

Manual processing would require opening each txt file, individually selecting lines like Annex A through Annex D, deleting them, and then saving. The more files there are, the more obvious the repetitive work becomes. Even more troublesome is that different files might contain Annex E, Annex F, or other letters. Searching only for fixed text makes it easy to miss some. Therefore, using wildcard regular expressions for batch matching is a more reliable approach.

Post-Processing Effect: Matched Annex Lines Have Been Batch Deleted

After the process is complete, opening the generated text file reveals that the content where Annex A, Annex B, Annex C, and Annex D were previously located is no longer present. Only the "Annexes" title and the subsequent "Contents" remain. The position marked by the red box shows the target lines have been cleaned, making the file content more concise.

image-Batch delete text lines,TXT batch processing,wildcard regular expression delete lines,text file batch replacement

The status bar also shows a change in text length and line count. Before processing, the example file displayed a length of 794 and 25 lines; after processing, it displays a length of 616 and 21 lines. This indicates the content wasn't simply hidden—the matched entire lines of text were actually deleted.

This effect is ideal for batch cleaning structured text. As long as the target content across multiple files shares a common pattern, you can complete multi-file processing with a single rule setup, avoiding the need to open, search, and save each file individually.

Operational Steps: Using HeSoft Doc Batch Tool to Batch Delete Matching Entire Lines

Step 1: Enter Text Tools and Select "Find and Replace Complete Lines in Text Files Based on Keywords"

After opening HeSoft Doc Batch Tool , select "Text Tools" from the left-hand function categories. The main interface will display various text-related functions, such as Find and Replace Keywords in Text, Delete Blanks in Text, Convert Text to Word, Convert Text to PDF, etc. According to the screenshot, you need to select the 2nd function: Find and Replace Complete Lines in Text Files Based on Keywords.

image-Batch delete text lines,TXT batch processing,wildcard regular expression delete lines,text file batch replacement

The emphasis of this function is on "complete lines." This means the software will search the text file for lines containing the user-defined keywords or expression and will perform a replacement or deletion on that entire line. This directly corresponds to the task in this article of deleting entire lines of content like Annex A, Annex B, etc.

Step 2: Add the TXT Files Needing Processing

After entering the function page, the interface banner shows the current function name, and the process is divided into stages: "Select Records to Process," "Set Processing Options," "Set Save Location," and "Start Processing." The first step requires adding the text files to be processed.

As seen in the screenshot, you can add individual or multiple files via "Add File," or import text files from a folder in bulk using "Import Files from Folder." In the example, five files have been imported, with the list showing details like sequence number, name, path, extension, creation time, and modification time. The extensions are all txt.

image-Batch delete text lines,TXT batch processing,wildcard regular expression delete lines,text file batch replacement

After adding files, it's advisable to check the list to ensure they are correct: do they include all the txt files intended for processing, are the paths targeting the correct folder, and do the extensions match expectations. If a file not intended for processing was added by mistake, it can be removed using the delete operation on the right side of the list. Once confirmed, click the "Next" button at the bottom to proceed to setting the processing rules.

Step 3: Select Fuzzy Search and Enter the Wildcard Regular Expression

On the "Set Processing Options" page, the first setting needed is the search method. In the screenshot, "Use formula for fuzzy text search" is selected. This option is suitable for entering expressions with wildcards or regex-like patterns to match a category of text with common patterns, rather than only matching completely identical fixed strings.

image-Batch delete text lines,TXT batch processing,wildcard regular expression delete lines,text file batch replacement

Enter the following into the "Keyword list to find":

Annex [A-Z]

This expression can be understood as matching content that starts with "Annex" followed by a space and then a single uppercase English letter. Therefore, lines like Annex A, Annex B, Annex C, and Annex D will all be identified. Since the current function processes the "complete line containing the keyword," if any part of a line matches the expression content, the entire line will be processed.

On the right is the "Keyword list for replacement." This area is empty in the screenshot, and the interface prompts "If left blank, it means delete." Therefore, if the goal is to delete the matched complete lines, do not enter any replacement content on the right. This will cause the software to delete the matched entire line during processing instead of replacing it with other text.

Step 4: Continue to Set Save Location and Start Processing

After setting up the keyword rules, click the "Next" button at the bottom of the page. According to the process bar, the subsequent steps involve "Set Save Location" and "Start Processing." The purpose of this step is to ensure the processed files have a clear output location, avoiding confusion with the original files and facilitating a unified review of the results after processing is complete.

When batch processing text files, it is recommended to save the results to a separate folder or use the software's save process to generate new files. This way, even if the expression settings do not meet expectations, you can return to the original files for reprocessing, reducing the risk of accidental deletion. After confirming the save location, proceed to the start processing stage and wait for the software to sequentially execute the rules on the files in the list.

Frequently Asked Questions and Precautions

1. Why use Annex [A-Z] instead of entering Annex A, Annex B individually?

If you only need to delete Annex A through Annex D, entering them individually would also work. However, in practice, different files might have Annex E, Annex F, or even more letters. Using Annex [A-Z] can cover A to Z uppercase letters at once, making the rule more universal and better aligned with the efficiency goals of batch processing.

2. What is the effect of leaving the replacement list on the right empty?

As the prompt in the screenshot indicates, "If left blank, it means delete." This means the left side is for searching, and if no replacement content is filled in on the right, the software will delete the matched content. Combined with the "complete line" characteristic of this function, the final effect is the deletion of the entire line containing the matching keyword.

3. Could it delete content that shouldn't be deleted?

Caution is required with any batch deletion operation. It's recommended to test the expression on a small sample of files first, such as processing one or two txt files, and verify the results are correct before expanding to all files. The broader the expression, the wider the matching range; the more precise the expression, the lower the probability of accidental deletion.

4. Can this method only handle TXT files?

The screenshots in this article show a txt text file processing flow, and the function name also clearly points to text files. For formats like Word documents (docx, doc), PDFs, etc., you should select the corresponding function under the software's Word tools or PDF tools accordingly, and not directly apply the text file processing workflow.

Summary: Replacing Repetitive Manual Deletion with Batch Text Processing

Using HeSoft Doc Batch Tool 's "Find and Replace Complete Lines in Text Files Based on Keywords" function, you can batch delete lines matching a rule across multiple TXT files at once. The example in this article used Annex [A-Z] to match appendix lines like Annex A to Annex Z and left the replacement list blank to execute a deletion, successfully cleaning the target lines from the text files.

If you frequently need to organize large numbers of text files, log files, or export lists, it's no longer advisable to open and manually delete content file by file. A more efficient approach is to first analyze the patterns of the target content, then set up unified rules using wildcard regular expressions, and let a batch processing tool complete the task automatically. This saves time and leads to more consistent processing results.


Keyword:Batch delete text lines , TXT batch processing , wildcard regular expression delete lines , text file batch replacement
Creation Time:2026-07-04 06:35:35

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!