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

[文件操作] 如何用批处理实现UNIX中的命令grep?

  小弟刚刚批处理入门.有问题像各位高手请教!如何用批处理实现unix中的grep命令啊!以下是grep的-v.-c,-n,-i的实现.可是-l功能不会实现.即在多文件搜索匹配字符时,如何只显示含有匹配字符的文件的文件名啊!帮帮忙,告诉我怎么实现吧~谢谢啊!
@echo off
if "%1"=="" goto forhelp
if "%1"=="--help" goto help
set %var=find
goto findoperation
goto end


:forhelp
::forhelp switch
echo Usage: grep [OPTION]... PATTERN [FILE]...
echo Try `grep --help' for more information.
goto end

:help
::help switch
echo Usage: grep [OPTION]... PATTERN [FILE] ...
echo Search for PATTERN in each FILE or standard input.
echo Example: grep -i 'hello world' menu.h main.c
echo -v  显示所有不包含指定 string 的行。  
echo -c  计算包含指定 string 的行并显示总数。  
echo -n  将文件行号置于每行开头。  
echo -i  指定搜索不区分大小写。  
goto end

:findoperation
if "%1"=="" call %var%&goto end
if "%1"=="-v" set var=%var% /V&shift&goto findoperation
if "%1"=="-n" set var=%var% /N&shift&goto findoperation
if "%1"=="-i" set var=%var% /I&shift&goto findoperation
if "%1"=="-c" set var=%var% /C&shift&goto findoperation
set var=%var% "%1"&shift&goto findoperation
:end
::the end of the .bat

findstr /m
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

返回列表