我在空白行上打开/关闭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.
答案 0 :(得分:1)
要消除当行为空(或空格,否则为空白)时ECHO IS OFF(或ON)消息,则只需使用ECHO(%%b
而不是ECHO %%b
。
传统上,人们使用ECHO.
来消除空白行的问题。但是在某些晦涩的情况下,这可能会引起问题。
ECHO(
始终有效。
答案 1 :(得分:0)
if "!test!" == []
将永远不会匹配。不要使用空格。
If "%string%"==""
如果字符串为空,则执行某些操作。