You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Notepad++或编辑器中筛选不匹配指定数字的文本行?

Hey there! Let's walk through how to filter out the lines in original.txt that don't match any numbers from text1.txt, plus break down whether a batch script is the better call here.


方法1:用Notepad++手动处理

This is perfect for one-off tasks with smaller files:

  1. Prepare your regex pattern:
    • Open text1.txt in Notepad++. Press Ctrl+H to open the Replace menu.
    • Replace all spaces ( ) with newlines (\n) — this turns each number into its own line.
    • Replace all newlines (\n) with pipes (|), then wrap the entire string in parentheses (e.g., (00124573|00758392|...)). Copy this pattern.
  2. Mark matching lines in the CSV:
    • Open original.txt, press Ctrl+F and switch to the Mark tab.
    • Paste your regex pattern into the "Find what" box, then tweak it to target the second CSV column: ^.*,(00124573|00758392|...),.*$ (make sure the number group matches your prepared pattern).
    • Check the "Regular expression" box, then click Mark All — all lines with a matching number will be tagged.
  3. Remove matched lines & save:
    • Go to Search > Bookmarks > Remove Bookmarked Lines. The remaining lines are your unmatched entries.
    • Save the file as a new document (e.g., unmatched_lines.txt).

方法2:批处理脚本自动化

If you need to run this task repeatedly, or have large files that would slow down Notepad++, a batch script is way more efficient. Here's a ready-to-use script:

@echo off
setlocal enabledelayedexpansion

:: Configure your file names here
set "number_file=text1.txt"
set "csv_file=original.txt"
set "output_file=unmatched_lines.txt"

:: Create a temporary file with one number per line
set "temp_num_list=temp_numbers.txt"
for /f "delims=" %%a in (%number_file%) do (
    echo %%a >> %temp_num_list%
)

:: Clear the output file first
type nul > %output_file%

:: Loop through each line in the CSV
for /f "usebackq delims=" %%b in (%csv_file%) do (
    :: Extract the second column (the number we need to check)
    for /f "tokens=2 delims=," %%c in ("%%b") do (
        :: Check if the number exists in our temp list
        findstr /x "%%c" %temp_num_list% >nul
        :: If it doesn't exist, write the line to output
        if errorlevel 1 (
            echo %%b >> %output_file%
        )
    )
)

:: Clean up the temporary file
del %temp_num_list%

echo Done! Unmatched lines saved to %output_file%
pause

Just save this as filter_unmatched.bat, place it in the same folder as your text files, and double-click to run.


Which approach is better?

  • Notepad++ wins for one-off, small tasks: It's visual, no coding needed, and quick to set up if you only need to do this once.
  • Batch scripts are better for automation/large files: They handle big datasets faster, can be run repeatedly without manual work, and avoid lag or crashes in text editors with huge files.

内容的提问来源于stack exchange,提问作者Kevdog777

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:41:19