[英]Extracting A List Of Phrases From A Large TXT File, And Writing A Single TXT File With Each Phrase (Also the title of that file)
我有一个术语列表,我有大量的文本文件,其中包含一些术语。 我的任务是为与原始文本文件在同一目录中的每个术语提供一个文本文件。
之前
listofterms.txt(苹果核心,桃子,烤牛肉,紫菜包裹的东西等......)
LargeFileOfFoodWords.txt(范围从20-20,000个单独的非重复文本行)
后
apple cores.txt,peaches.txt,roast beef.txt,包装在nori.txt中的东西(等等......)
LargeFileOfFoodWords.txt(原始文件,未更改 - 或者如果可能,提取所有'listofterms')
使用以下bat文件,我可以使用单个单词执行此操作。 但是,生成的文件包含批处理文件所在目录中所有文件的路径。连续搜索还包括apple cores.txt,peaches.txt等...
所以我有一些元素在工作,需要调整以下内容:
如果您希望自己测试,此脚本将与任何.txt文件一起使用,并为您提供结果“SearchTerm.txt”。
@echo off
set RESULT_FILE="result.txt"
set /p "buck1=Enter Bucket Word or Phrase to find:"
pushd %~p0type NUL > %RESULT_FILE%.tmp
for /f "delims=" %%a in ('dir /s/-b/l *.txt')
do (for /f %%c in ('find /i /c "%buck1%" "%%a"')
do (for /f "tokens=*" %%f in ('find /i "%buck1%" "%%a"')
do if %%c neq 0 echo :`%%f))>>"%RESULT_FILE%".tmp
move %RESULT_FILE%.tmp %buck1%.txt >nul 2>&1
popd
这可能适合你:
for /f "delims=" %%a in ('findstr /xg:listofterms.txt LargeFileOfFoodWords.txt') do (type nul>"%%~a.txt"&echo(%%~a>"result.txt")
如需更多帮助,请输入help for
和help findstr
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.