SHELL批量命令:grep命令-ev [英] SHELL to BATCH : grep -Ev command

查看:1775
本文介绍了SHELL批量命令:grep命令-ev的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助。我有这样的shell脚本code和工作正常。

I need some help. I have this shell script code and it is working properly.

 databases=`mysql -u$dbUser -p$dbPass -e "SHOW DATABASES LIKE '%demo%';"  | grep -Ev "(Database|information_schema)"`

我怎样才能把它转换批处理?

How can I convert it in Batch?

推荐答案

您可以使用此作为基础,并适应您的需求。

You can use this as a base and adapt to your needs.

@echo off
    setlocal enableextensions enabledelayedexpansion

    set "dbUser=username"
    set "dbPass=password"

    set "databases="
    for /f "usebackq delims=" %%a in (`
        mysql -u%dbUser% -p%dbPass% -e "SHOW DATABASES LIKE '%%demo%%';" 
        ^| findstr /l /v /c:"Database" /c:"information_schema"
    `) do set "databases=!databases! %%a"

    echo %databases%

命令将执行的mysql 命令,将与 FINDSTR进行过滤为不包含所指示的字符串的行。对于每个输出线,在子句中的code被执行。每个输出线连接到此数据库变量。

The for command will execute the mysql command, that will be filtered with findstr for lines that do not contain the indicated strings. For each of the output lines, the code in the do clause is executed. Each output line is concatenated to the databases variable.

这篇关于SHELL批量命令:grep命令-ev的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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