[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
  1. type a*.txt | findstr "1"
复制代码

TOP

本帖最后由 tmplinshi 于 2011-7-19 16:14 编辑

3# ftjm268
  1. type a*.txt 2>nul | find /c "1" >b.txt
复制代码
2>nul 可要可不要,不会影响结果,不加 2>nul 的话文件名会显示在 cmd 窗口。

TOP

3# ftjm268 type a*.txt |findstr /v "a.*\.txt"|find /c "1"
zm900612 发表于 2011-7-19 15:43

type 输出的文件名,是输出到了 standard error。
1

评分人数

    • zm900612: 这个细节很关键,学习了技术 + 1

TOP

本帖最后由 tmplinshi 于 2011-7-19 17:29 编辑

因为 findstr "382 -VB814266" 查找的是两个关键词 "382" 和 "-VB814266"。
  1. @echo off
  2. set str="1"
  3. set file="110715*.txt"
  4. type %file% 2>nul | findstr /c:%str% >sum.txt
  5. for /f %%a in (' "type %file% 2>nul | find /c %str%" ') do set n=%%a
  6. echo %n%
  7. pause
复制代码

TOP

@echo off
set str="382 -VB814266"
set file="110715*.txt"
type %file% 2>nul | findstr /c:%str% >sum.txt
for /f %%a in (' "type %file% 2>nul | find /c %str%" ') do set n=%%a
echo %n%
pause


是不是你忘记修改红色部分了?

TOP

加上 /i 参数忽略大小写:
:echo off
u:
cd MTN\OPSDATA_BKUP
set str="382 -v143788"
set file="200718*.txt"
type %file% 2>nul | findstr /i /c:%str% >sum.txt
for /f %%a in (' "type %file% 2>nul | find /i /c %str%" ') do set n=%%a
echo %n%
pause

N=0


-------------------

2>nul 是用来屏蔽错误输出。
1

评分人数

    • ftjm268: 给予我很大的技术支持技术 + 1

TOP

本帖最后由 tmplinshi 于 2011-7-22 13:48 编辑
19# tmplinshi
type %file% 2>nul | findstr /i /c:%str% >sum.txt
for /f %%a in (' "type %file% 2>nul | find /i /c %str%" ') do set n=%%a
本人新手,在学习中。有点不明白。为什么用了findstr还要用find呢 ...
q115643492 发表于 2011-7-22 11:10

为了代码更简短、易读。
可以像 9 楼 一样只用一个 find。

TOP

返回列表