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


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

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!

This article describes how to use HeSoft Doc Batch Tool to match specified content across multiple TXT text files using wildcards or regular expressions, and batch delete entire lines containing that content. In the example, you need to delete all appendix lines appearing in the form of Annex A, Annex B, Annex C, etc. Simply import multiple text files, select the keyword-based find and replace complete line feature, enable formula-based fuzzy text search, input the matching rules, and leave the replacement content empty. This allows you to complete multi-file cleanup in one go, reducing the repetitive operations of opening, searching, and deleting individually.

When organizing data, cleaning text data, processing exported system logs, or batch modifying document content, a common problem arises: many TXT text files contain similar lines, such as appendix entries like Annex A, Annex B, Annex C, Annex D, etc. The description text afterwards may differ, but these entire lines are no longer needed. If there is only one file, manually opening a text editor to delete a few lines is not much trouble; however, when the number of files grows to dozens or hundreds, opening, searching, selecting, deleting, and saving each one is not only time-consuming but also prone to omission or accidental deletion.

This article addresses this typical batch processing problem for office files: using HeSoft Doc Batch Tool , you can batch delete complete lines matching a condition in multiple TXT text files through wildcard or regular expression rules. In the example, we will delete lines containing patterns from Annex A to Annex Z in multiple text files at once, while retaining other body text. For users needing to batch clean text, batch replace text, batch delete log lines, or batch process txt files, this method can significantly reduce repetitive work.

Applicable Scenarios: Which situations are suitable for batch deleting entire lines with regex

This type of operation is suitable for processing text files with similar content structures but not exactly the same specific text. For instance, each file might have several lines starting with a fixed prefix, followed by different numbers, letters, or descriptions. Using an ordinary exact search requires entering multiple keywords like Annex A, Annex B, Annex C separately; by using a regular expression or wildcard rule, you only need to write one matching pattern to cover a group of similar content.

Common scenarios include: batch deleting appendix directory lines in TXT files; batch deleting entire lines containing a certain type of error code in log files; batch cleaning unwanted entries in configuration files; batch deleting temporary marker lines in exported text; batch removing lines containing specified keywords; batch organizing plain text content converted from web pages, PDF, Word, docx, or doc documents. For office software, the core value is not just opening files, but automating and batching repetitive processing actions.

The files in this example are multiple TXT text files, named from 1.txt to 5.txt. They are placed in the same folder, ready for unified deletion rule execution.

image-Batch delete text lines,regular expression delete entire lines,TXT batch processing,text file batch replacement,office software batch file processing

Effect Preview: Before processing, containing multiple lines of Annex appendix content

From the screenshot before processing, it can be seen that the text file contains a section of Annexes, where lines 3 to 6 are entries starting with Annex A, Annex B, Annex C, and Annex D respectively. These lines are followed by different descriptive texts, such as Food and drink standards, The secondary school analysed meal, Frequently asked questions, etc. Their commonality is that they all start with Annex, a space, and a capital letter.

image-Batch delete text lines,regular expression delete entire lines,TXT batch processing,text file batch replacement,office software batch file processing

If deleting manually, one would need to locate these lines in each text file and delete them line by line. Even for 5 files, it requires repeated operations; for 50 or 500 text files, the workload would quickly escalate. More importantly, manual deletion is prone to two problems: missing a line in a certain file, and accidentally deleting adjacent body content. Using a batch processing tool with rule matching standardizes the operation and reduces human error.

Post-Processing Effect: Matched entire lines are deleted, body table of contents retained

After processing is complete, upon opening the text file again, the original lines from Annex A to Annex D have been deleted, while the subsequent Contents and directory number content remain. That is, this operation does not simply delete a few characters, but processes the entire line after matching a line containing the specified pattern; when the replacement content is empty, this achieves the effect of deleting the entire line.

image-Batch delete text lines,regular expression delete entire lines,TXT batch processing,text file batch replacement,office software batch file processing

It can also be seen from the screenshot that the number of lines in the file changed from 25 before processing to 21 after processing, indicating that 4 Annex-related lines have been removed. This result is very suitable for batch text cleaning: content that meets the rule is uniformly deleted, and un-matched body text is unaffected.

Operation Step 1: Enter the text tool and choose to process complete lines by keyword

After opening HeSoft Doc Batch Tool , select the Text Tool from the left-side category. This software is positioned as a document batch processing office software, providing various batch processing functions for files such as text, Word, Excel, PowerPoint, PDF, etc. Since we are processing TXT text files this time, simply enter the Text Tool category.

In the function list, select "Find and replace complete lines in text files based on keywords." The description of this function in the screenshot is "Batch delete or replace entire lines containing a certain keyword in text files with new text," which exactly matches the need of this article: we are not just replacing a word, but deleting entire lines containing a certain pattern.

image-Batch delete text lines,regular expression delete entire lines,TXT batch processing,text file batch replacement,office software batch file processing

The purpose of choosing this function is to let the software process text content line by line. Ordinary find and replace usually only changes the matched characters, while complete line processing locates the entire line based on the matched keyword or expression, then executes the replacement or deletion. For batch deleting lines containing specified content, this step is crucial.

Operation Step 2: Add TXT files to be batch processed

After entering the function page, the first step is to select the records to be processed. In the upper right corner of the interface, you can see action buttons like Add File, Import Files from Folder, Clear, More, etc. The example has already imported 5 TXT files, and the list displays information such as serial number, name, path, extension, creation time, and modification time.

image-Batch delete text lines,regular expression delete entire lines,TXT batch processing,text file batch replacement,office software batch file processing

If the number of files is small, you can use Add File to select them one by one; if multiple text files are located in the same directory, it is more recommended to use Import Files from Folder, which can add all TXT files in the folder to the task list at once. After importing, it is necessary to check if the files in the list are correct, especially paths and extensions. The file extensions in the example are all txt, the path is in the D:\test directory, and the record count is 5, indicating that these 5 files will all participate in the subsequent batch processing.

The expected outcome of this step is: all text files to be processed appear in the task list, and no files that should not be processed are included. If files are added by mistake, you can delete the corresponding records according to the operation column in the interface to avoid affecting irrelevant files.

Operation Step 3: Set the search method to formula-based fuzzy text search

After confirming the file list, click Next to proceed to the processing options settings. In the keyword settings area, you can see the search method. The example chooses "Use formula for fuzzy text search" instead of "Exact text search." "Formula fuzzy text search" here can be understood as using more flexible matching rules, suitable for handling content like Annex A, Annex B, Annex C, which has the same format but different specific letters.

image-Batch delete text lines,regular expression delete entire lines,TXT batch processing,text file batch replacement,office software batch file processing

Enter Annex [A-Z] in the list for keywords to find. The meaning of this rule is to match text with Annex followed by a space and a capital English letter. Since this function processes the complete line containing the keyword, as long as a line matches this pattern, that entire line will be treated as the target. In the example, Annex A, Annex B, Annex C, and Annex D all conform to this rule, so they will all be deleted.

The keyword list for replacement on the right side should be kept empty. The interface also prompts that leaving it blank indicates deletion, so when the software finds matching lines, it will directly remove them rather than replacing them with other text. This setting is the core of achieving batch deletion of entire lines.

If your text has a different format from Annex A, you can also adjust the rule based on the actual content. For example, to delete lines containing "Chapter" followed by a number, you can use a rule like Chapter [0-9]; to delete lines where a fixed keyword is located, you can use the exact search method to enter the fixed text. The actual rule should be based on the matching syntax supported by the software and your text structure; it is recommended to test with a small number of files first.

Operation Step 4: Continue to set the save location and start processing

After setting the search rules and replacement content, click the Next button at the bottom of the page. In the interface flow, you can see subsequent stages for Setting Save Location and Start Processing. The setting of the save location is very important, because batch modification of text files is a data processing operation that cannot be taken lightly. It is recommended to prioritize output to a new location or keep a backup, and confirm the results are correct before replacing the original files.

After entering the Start Processing stage, execute the processing according to the interface prompts. The software will read the content of the text files one by one based on the previously imported file list, find complete lines containing the Annex [A-Z] rule, and delete these lines when the replacement content is empty. After processing, open the output files to verify that lines like Annex A, Annex B have disappeared, while the Contents and subsequent directory content remain.

The expected outcome of this step is: multiple TXT files are processed uniformly, eliminating the need for users to repeatedly open each file for manual deletion. For batch file cleaning tasks, this is where the real time-saving lies: set the rule once, and the software automatically executes it for multiple files.

Frequently Asked Questions and Notes

1. Why choose complete line processing over ordinary replacement?

Because the goal of this article is to delete entire lines. Ordinary replacement usually only deletes the few matched characters like "Annex A," possibly leaving the subsequent descriptive text behind, leading to a disrupted text structure. After selecting "Find and replace complete lines in text files based on keywords," as long as a line contains the matched content, the entire line can be deleted or replaced.

2. Why should the replacement keyword list be left empty?

The right-side area in the screenshot prompts that leaving it blank indicates deletion. That is, when you want to delete the matched complete line, you do not need to enter replacement text. If other content is entered, the software might replace the matched entire line with the new text you filled in, rather than deleting it.

3. What content does Annex [A-Z] match?

In this example, it is used to match content with Annex followed by a capital letter, such as Annex A, Annex B, Annex C. Since the appendix lines in the sample text all conform to this pattern, it can cover multiple different items at once. When using such rules, pay attention to whether spaces, case, and letter ranges are consistent with the original text.

4. Does this affect Word, docx, doc, or PDF files?

This article demonstrates TXT text file processing in the Text Tool. Word documents, docx, doc, PDF files, etc., have their own document structures and cannot be simply equated to plain text files. If your content comes from Word or PDF, you can first convert it to TXT based on actual needs, then use the text batch processing function; or select the corresponding Word Tool or PDF Tool function in the software.

5. Is a backup needed before batch processing?

Backups are recommended. Regex or wildcard rules are very efficient, but this also means that if a rule is written too broadly, it might delete more lines than expected. Especially when processing a large number of files for the first time, it is advisable to first copy a few sample files for testing, confirm the post-processing effect matches expectations, and then execute batch processing on all files.

Summary: Turning repetitive deletion into a single rule setting with a batch processing tool

Batch deleting specified lines from multiple text files is essentially a highly repetitive, low-creativity office task. Manual processing consumes a lot of time and makes it difficult to ensure perfect consistency across every file. With HeSoft Doc Batch Tool , such operations can be transformed into a standard process: import TXT files, select the complete line find and replace function, enable formula-based fuzzy text search, enter a matching rule like Annex [A-Z], leave the replacement content empty, and then execute in batch.

In this way, users do not need to open files like 1.txt, 2.txt, 3.txt one by one, nor do they need to repeat searching and deleting. For office workers who frequently handle logs, data directories, exported text, and batch TXT files, mastering this regex-based method for batch deleting entire lines can significantly reduce repetitive work and improve text cleaning efficiency. It is recommended to first validate the rules with a small number of sample files before applying them to a complete folder, which is both efficient and safe.


Keyword:Batch delete text lines , regular expression delete entire lines , TXT batch processing , text file batch replacement , office software batch file processing
Creation Time:2026-07-04 06:38:02

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!