简体   繁体   中英

How to set Echo on/off for file manipulation

I have an issue with echo on/off on blank rows. I have tried multiple things, including echo variable among other things.

Here is the code I currently am using along with the log and the current output after I use the script to parse records with some records being blank that I want to have remain blank.

Current Code

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)
)

Current Output (Note that I need to retain the 3 blank lines that currently have "ECHO is off")

#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.

Current Log - After Execution for this code (as you can see this is evidence of why I am getting it in the output for a blank line? When there isn't a blank line you get the results but they aren't showing in the log

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.

To eliminate the ECHO IS OFF (or ON) message when the line is empty (or nothing but whitespace), then simply use ECHO(%%b instead of ECHO %%b .

Traditionally people used ECHO. to eliminate problems with blank lines. But there are some obscure situations where that can cause problems.

ECHO( always works.

if "!test!" == [] if "!test!" == [] will NEVER match. Don't use spaces.

If "%string%"=="" does something if string is blank.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM