首页 > 解决方案 > 如何为文件操作设置 Echo 开/关

问题描述

echo对空白行的开/关有疑问。我尝试了多种方法,包括echo变量等。

这是我当前使用的代码以及日志和在我使用脚本解析记录后的当前输出,其中一些记录是空白的,我希望保持空白。

当前代码

for /f "skip=%skipTo% tokens=1,* delims=]" %%a In ('type %InputFile% ^| find /v /n ""') do (
    set ip=%%b
    set ip=!ip:!
    set test=!ip!
    echo !ip!
    echo(!test!

    if "!test!" == [] (
        !test! >> E:\EPM_Cloud\LoadFiles\BUD_PLN\Security\GROUPS_USERS_CURRENT_LIST.csv
    ) else (echo %%b >> E:\EPM_Cloud\LoadFiles\BUD_PLN\Security\GROUPS_USERS_CURRENT_LIST.csv)
)

当前输出(请注意,我需要保留当前具有“ECHO 已关闭”的 3 个空白行)

#group_children 
id,group_id,group_provider,user_id,user_provider 
BL_LEAD,,,TestUser_2,LDAP_Directory_Provider 
BL_LEAD,,,angelo.vergura@nrc.gov,LDAP_Directory_Provider 
ECHO is off.
ECHO is off.
 ECHO is off.
#group_children 
id,group_id,group_provider,user_id,user_provider 
NON_BL_LEAD,,,Christopher.George@nrc.gov,LDAP_Directory_Provider 
NON_BL_LEAD,,,Lindsey.Heeszel@nrc.gov,LDAP_Directory_Provider 
NON_BL_LEAD,,,Safa.Kaleem@nrc.gov,LDAP_Directory_Provider 
NON_BL_LEAD,,,Susan.Orbach@nrc.gov,LDAP_Directory_Provider 
NON_BL_LEAD,,,Tung.Truong@nrc.gov,LDAP_Directory_Provider 
NON_BL_LEAD,,,angelo.vergura@nrc.gov,LDAP_Directory_Provider 
NON_BL_LEAD,,,arodriguez,LDAP_Directory_Provider 
NON_BL_LEAD,,,camason@huronconsultinggroup.com,LDAP_Directory_Provider 
NON_BL_LEAD,,,jeffrey.sheldon@nrc.gov,LDAP_Directory_Provider 
NON_BL_LEAD,,,larry.mason@nrc.gov,LDAP_Directory_Provider 
NON_BL_LEAD,,,mary.moshier@nrc.gov,LDAP_Directory_Provider 
NON_BL_LEAD,,,sreekanth.manne@nrc.gov,LDAP_Directory_Provider 
ECHO is off.
ECHO is off.
ECHO is off.

当前日志- 执行此代码后(如您所见,这证明了为什么我在输出中得到它的空行?当没有空行时,您会得到结果,但它们没有显示在日志

ECHO is off.

ECHO is off.

ECHO is off.

ECHO is off.

ECHO is off.

ECHO is off.

ECHO is off.

ECHO is off.

ECHO is off.

ECHO is off.

ECHO is off.

ECHO is off.

ECHO is off.

ECHO is off.

ECHO is off.

标签: windowsshellbatch-fileoperating-system

解决方案


要在该行为空(或只有空格)时消除 ECHO IS OFF(或 ON)消息,然后只需使用ECHO(%%b代替ECHO %%b.

传统上,人们习惯于ECHO.消除空白行的问题。但是有一些模糊的情况可能会导致问题。

ECHO(总是有效。


推荐阅读