When multiple TXT text files contain the same invalid lines, directory lines, marker lines, or content with fixed keywords, opening each file individually for deletion is time-consuming and prone to omissions. This article uses HeSoft Doc Batch Tool as an example to demonstrate how to use the text tool function in office software to batch find complete lines containing specified keywords in text files, and achieve batch deletion by leaving the replacement content empty. This is suitable for processing large numbers of TXT logs, lists, exported texts, and data directories.
In daily office work, document organization, system log cleanup, data export verification, and similar scenarios, a common problem often arises: a folder contains many TXT text files, each of which includes some unwanted lines, such as directory lines with a fixed prefix, description lines containing a specific number, or record lines with sensitive words or invalid markers. If it's just one or two files, manually opening and deleting them is acceptable; but if there are dozens or hundreds of text files, searching and deleting line by line one at a time is not only time-consuming but also prone to omissions.
The core problem this article aims to solve is: how to batch delete all lines containing specified keywords in many text files. The "delete line" here does not mean simply deleting a word, but removing the entire line from the text file if it contains the set keyword. The example requires deleting lines containing Annex A, Annex B, Annex C, and Annex D. After processing, these lines will disappear simultaneously from multiple txt files.
Below, using the office software " HeSoft Doc Batch Tool " shown in the screenshot as an example, the specific operation method is introduced. This tool is positioned as a document batch processing office software, suitable for batch organizing office files such as text, Word, PDF, and Excel. It can reduce repetitive clicking and mechanical operations, making it especially suitable for office scenarios that require processing multiple files at once.
Applicable Scenarios: Situations Suitable for Batch Deleting Lines Containing Keywords
Batch deleting keyword lines in text files is applicable to many common office and data processing scenarios. As long as the files are in txt text format and the content to be deleted can be identified by keywords, this batch processing method can be considered.
- Batch cleaning TXT directory lines: For example, each text file contains directory or appendix lines like Annex A, Annex B that need to be uniformly deleted.
- Batch deleting invalid records in logs: For example, deleting entire lines containing keywords like error, debug, test, temp, invalid.
- Batch processing exported text: Text files exported from a system might contain repetitive headers, explanatory notes, or page number markers that need unified removal.
- Batch cleaning sensitive information: If some lines contain keywords like phone numbers, email markers, or customer IDs, the entire line can be deleted based on the keyword.
- Batch organizing databases: Fixed-format useless description lines in multiple txt files can be deleted all at once, avoiding editing file by file.
Compared to ordinary text editors, the advantage of batch processing tools is that you don't need to open files one by one, nor repeatedly execute find and delete operations. Simply import the files into the tool, set up the keyword list, and the same rule can be executed on multiple text files simultaneously.
Effect Preview: Changes Before and After Processing
Before Processing: Multiple TXT Text Files in the Folder
From the pre-processing screenshot, it can be seen that the directory to be processed contains multiple text files such as 1.txt, 2.txt, 3.txt, 4.txt, 5.txt. If these files are opened and modified one by one, the same find, locate, delete, and save operations need to be repeated. The larger the number of files, the more obvious the time spent.

Before Processing: Text Content Contains Lines with Keywords to be Deleted
Opening one of the text files shows that the beginning of the file contains multiple lines including Annex A, Annex B, Annex C, Annex D. Although these lines are followed by different descriptive text, their common feature is containing the fixed keywords Annex A, Annex B, Annex C, Annex D. Therefore, the complete lines containing these keywords can be deleted at once through keyword matching.

After Processing: Entire Lines Containing Keywords Have Been Deleted
After processing is complete, opening the result file shows that the multiple lines originally containing Annex A, Annex B, Annex C, Annex D are no longer in the text, while the subsequent Contents and main body numbered content are preserved. That is, the software executes "locating the entire line by keyword and deleting the entire line," not just deleting a few characters within the line.

From the change in the number of lines in the screenshot, it can also be seen that the pre-processing text had more lines, while after processing, the lines containing the specified keywords were removed, making the text structure cleaner. This effect is very suitable for batch cleaning directories, descriptions, invalid records, or repetitive headers.
Operation Steps: Using Office Software to Batch Delete Entire Lines Containing Keywords in TXT Files
Step 1: Enter the Text Tool and Select the Function for Processing Complete Lines by Keyword
After opening HeSoft Doc Batch Tool , select "Text Tool" from the function categories on the left. In the function list, find "Find and replace complete lines in text files based on keywords." The description of this function in the screenshot is to batch delete or replace entire lines containing a certain keyword in text files with new text, which fits this requirement perfectly.

The purpose of this step is to enter the functional module specifically designed for processing complete lines in text files. Unlike the ordinary "find and replace text keywords" function, this function's processing target is the "complete line." That is, as long as a keyword is hit in a line, the entire line will be processed. If the replacement content is empty, it achieves full-line deletion.
Step 2: Add TXT Files to be Batch Processed
After entering the function page, the first step is to "select records to process." On the interface, operation entries such as "Add File," "Import Files from Folder," "Clear," and "More" can be seen. The example already has five files imported: 1.txt to 5.txt. The list displays the file name, path, extension, creation time, and modification time.

If the number of files is small, you can select specific txt files via "Add File"; if all files to be processed are in the same folder, you can use "Import Files from Folder" to import them at once. After importing, it is recommended to check the file names and extensions in the list to confirm they are all text files intended for this processing, avoiding accidentally processing other files.
The expected result of this step is: all txt files from which keyword lines need to be deleted appear in the processing list. The bottom of the screenshot shows a record count of 5, indicating that the same batch rule will be executed on five text files currently.
Step 3: Set Search Mode and Keyword List
Clicking "Next" leads to "Set Processing Options." As seen in the screenshot, the search mode is set to "Exact Text Search." The left area is the "Keyword List to Find," where Annex A, Annex B, Annex C, Annex D are filled in sequentially. The right area is the "Replacement Keyword List," with a prompt stating "Leaving blank means deletion."

The goal this time is to delete entire lines containing these keywords, so there are two key points: first, enter the keywords to match line by line in the keyword list to find; second, keep the replacement keyword list on the right empty. According to the interface prompt, leaving the replacement content empty means deleting the matched complete lines.
In the example, the lines to be deleted in the file start with Annex A, Annex B, Annex C, Annex D respectively, so these four keywords are entered into the keyword list. During processing, the software will search for lines containing these keywords in each imported txt file. If a line matches one of the keywords, that line will be deleted.
If the actual content you want to delete in your files is different, you can replace them with your own keywords as needed. For example, to delete all lines containing "temporary data," enter "temporary data"; to delete log lines containing "debug," enter "debug"; to delete multiple markers, put each keyword on a separate line for clear rules.
Step 4: Continue to the Next Step, Set Save Location, and Start Processing
After setting the keywords, click the "Next" button at the bottom of the page. According to the interface workflow, subsequent steps include "Set Save Location" and "Start Processing." Before batch modifying file content, it is recommended to first select a clear output location to easily distinguish the processed files from the original ones.
Once the save location is set, proceed to the start processing step. The software will batch scan each text file according to the previously imported file list and keyword rules, and delete the complete lines containing the specified keywords. After processing is complete, spot-check the output results to confirm that the lines containing keywords have been deleted and other main body content remains.
The expected result of this step is: multiple txt text files are cleaned simultaneously without needing to manually open and edit them one by one. For directories containing a large number of text files, this method can significantly shorten processing time.
Precautions: Details to Confirm Before Batch Deleting
1. Keywords Should Be as Accurate as Possible to Avoid Deleting Normal Lines
Because this function deletes "the entire line containing the keyword," the more accurate the keyword setting, the lower the risk of accidental deletion. If the keyword is too short or too common, it might match lines that shouldn't be deleted. For example, entering only A might delete many lines containing the letter A; entering Annex A is closer to the actual target.
2. Distinguish Between Deleting Keywords and Deleting Entire Lines
This article uses the "find and replace complete lines in text files based on keywords" function, and the processing result is the deletion of the entire line. It is suitable for deleting directory lines, log lines, and marker lines. If your requirement is only to delete a word within a line, not the whole line, you should choose another corresponding text find and replace function.
3. Recommend Testing with a Small Number of Files First
Before processing a large number of files, you can select one or two sample files to test the rule. After confirming the processing results meet expectations, import the complete folder for batch processing. This can reduce rework caused by improper keyword settings.
4. Pay Attention to Text File Encoding and Line Break Format
The text editor in the screenshot shows the file is in UTF-8, Windows CR LF format. Generally, office software can handle common text files, but if encountering files with special encoding, it's recommended to spot-check the processing results first to ensure the Chinese, English, and line break structures are normal.
Common Questions
Can lines corresponding to multiple different keywords be deleted at once?
Yes. The screenshot has already demonstrated filling in four keywords: Annex A, Annex B, Annex C, Annex D in the keyword list. In actual operation, more keywords can be added as needed, with each keyword on a separate line, facilitating the software to match them one by one.
Why should the replacement keyword list on the right be left blank?
Because the interface prompt states "Leaving blank means deletion." If the current requirement is to delete entire lines containing keywords, do not fill in content in the replacement keyword list. If replacement content is filled in, it might turn into replacing the matched entire line with new text.
Can it process doc, docx, or PDF files?
This article demonstrates entire line processing in TXT text files. doc, docx, PDF are different document formats, and processing methods usually differ. If you need to process Word documents or PDF files, you should select the corresponding Word tools, PDF tools, or conversion functions within the office software, and not treat them directly as txt files.
Summary
The key to batch deleting all lines containing keywords in many text files lies in selecting the "process complete lines by keyword" function and correctly setting the keyword list. Through HeSoft Doc Batch Tool , the repetitive labor that originally required opening one by one, searching line by line, and deleting repeatedly can be transformed into an office workflow of importing once, setting once, and batch completing.
If you are organizing a large number of txt files, log texts, system export files, or data directories, it is recommended to first prepare a list of keywords to delete, then follow the steps in this article to import files, set keywords, leave the replacement content blank, and start processing. This can both reduce manual operations and improve the accuracy and efficiency of text cleaning.