bat批量提取关键词字符行

我的txt内有百万行,需要通过bat来批量处理提取关键词字符行
我的txt内容的格式为
随机内容aaa---随机内容
随机内容bbb---随机内容
随机内容aaa---随机内容
随机内容ddd---随机内容
随机内容aaa---随机内容

请帮我写一个bat,提取目标包含aaa或bbb的字符行,并且只要分隔符----前面的内容。
因为txt数据太多了,希望可以调用sed.exe来快速处理数据。

@echo off
rem 第三象限04
rem 2015年11月7日
rem 此处将%1替换为目标文件 路径名字
set source=%1
rem aaa bbb为匹配的关键字
set fextion=aaa bbb
set tempfile1=%temp%\tempfile1.log
set tempfile2=%temp%\tempfile2.log
if not exist %source% echo 读取文件不存在&pause>nul&exit /b 1
if exist %tempfile1% 0 0>%tempfile1% 2>nul
if exist %tempfile2% 0 0>%tempfile2% 2>nul

echo 正在匹配关键字
type %source%|findstr "%fextion%" >>%tempfile1%
for /f "tokens=1 delims=-" %%i in (%tempfile1%) do @(
echo %%i
)>>%tempfile2%
echo %source%目标包含%fextion%的字符行已全部存放%tempfile2%中
echo 是否查看(默认不查看)
choice /t 3 /d n
if "%errorlevel%"=="2" pause&exit /b 0
type %tempfile2% 
pause

最后取出的信息在%temp%\tempfile2.log 中

温馨提示:答案为网友推荐,仅供参考
相似回答