'FINDSTR“使用多个搜索结果(批) [英] 'findstr' with multiple search results (BATCH)

查看:306
本文介绍了'FINDSTR“使用多个搜索结果(批)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是根据我的最后一个问题的剧本:,<一个href=\"http://stackoverflow.com/questions/18028326/directory-mapout-is-not-working-batch/18029651?noredirect=1#18029651\">Directory mapout不工作(批)

This is based on my last question's script:, Directory mapout is not working (BATCH)

(对于整个脚本,请单击链接。但是,您可能只点击链接,如果从code以下喀嚓的目录mapout不能正常工作的并没有真正意义给你)

(For the whole script, click the link. However, you may only click the link if the following snip of code from "directory mapout is not working" does not really make sense to you)

<code>
cd temporary
set odir=%dir%
set /p cdir="DIRECTORY: " 
set domap=%cdir%
title SONOROUS FILE SEARCHER: Mapping out...
echo PLEASE WAIT, MAPPING OUT DIRECTORY.
dir %domap% /a-d /b /s > "tempres.rsm"
echo Directory Mapout done
echo -----------------------------
echo       DIRECTORY MAPOUT
set dirmapout=<tempres.rsm
echo %dirmapout%
echo -----------------------------
title SONOROUS FILE SEARCHER: Mapout done.
set /p "searchinput=Search Term: "
title SONOROUS FILE SEARCHER (Copyright 2013 by Sonorous)
for /f "delims=" %%a in ('findstr /i /L /c:"%searchinput%" "tempres.rsm" ') do set "found=%%a"
set proin=%found%
echo "%found%"
cd temporary
del "tempres.rsm"
</code>

我要的FOR / F从一个搜索词命令输出的许多搜索结果。
是code格式不正确?关于这个问题请留言/评论。

推荐答案

如果您只是想显示匹配行,则沟FOR / F共

If you simply want to display the matching lines, then ditch the FOR /F altogether

title SONOROUS FILE SEARCHER (Copyright 2013 by Sonorous)
findstr /i /L /c:"%searchinput%" "tempres.rsm"
cd temporary
del "tempres.rsm"

如果你需要一个匹配行的阵,则:

If you need an "array" of matching lines, then:

:: Define the array of matching lines
set "foundCount=0"
for /f delims^=^ eol^= %%a in ('findstr /i /L /c:"%searchinput%" "tempres.rsm" ') do (
  set /a "foundCount+=1"
  setlocal enableDelayedExpansion
  for %%N in (!foundCount!) do (
    endlocal
    set "found%%N=%%a"
  )
)

:: Display the array values
setlocal enableDelayedExpansion
for /l %%N in (1 1 %foundCount%) do echo match %%N = !found%%N!

这篇关于'FINDSTR“使用多个搜索结果(批)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆