Solved

Batch File Nested IF

Posted on 2010-09-16
5
1,350 Views
Last Modified: 2012-05-10
I am trying to add the last bolded ELSE . . . to this batch code without success.

I have tested both ELSE as good but can not add them together.

How do I get FOR /F to see multiple nested IF Statements?

FOR /F "Tokens=1-3,* Delims=^*" %%A IN ('Type "%SourceFile%"') DO IF "%%A%%B"=="NM1IL" (ECHO %%D >> "%OutputFile%") ELSE (IF "%%A%%B"=="NM185" ECHO %%D >> "%OutputFile%") ELSE (IF "%%A%%B"=="REFD9" ECHO %%C >> "%OutputFile%")
0
Comment
Question by:tonydemarco
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 56

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 33693991
FOR /F "Tokens=1-3,* Delims=^*" %%A IN ('Type "%SourceFile%"') DO (
  IF "%%A%%B"=="NM1IL" (
    ECHO %%D >> "%OutputFile%"
  ) ELSE (
    IF "%%A%%B"=="NM185" (
      ECHO %%D >> "%OutputFile%"
    ) ELSE (
      IF "%%A%%B"=="REFD9" ECHO %%C >> "%OutputFile%"
    )
  )
)
0
 
LVL 9

Author Closing Comment

by:tonydemarco
ID: 33694094
Excellent!
0
 
LVL 56

Expert Comment

by:Bill Prew
ID: 33694322
Thanks, glad that helped.

~p
0
 
LVL 9

Author Comment

by:tonydemarco
ID: 33695224
Wanting to Add:
IF "%%A"=="N3" (ECHO %%B >> "%OutputFile%"
to your solution below and should I be looking at an easier way to add to the search criteria?

Putting this in a new Question to follow . . .

FOR /F "Tokens=1-3,* Delims=^*" %%A IN ('Type "%SourceFile%"') DO (
  IF "%%A%%B"=="NM1IL" (
    ECHO %%D >> "%OutputFile%"
  ) ELSE (
    IF "%%A%%B"=="NM185" (
      ECHO %%D >> "%OutputFile%"
    ) ELSE (
      IF "%%A%%B"=="REFD9" ECHO %%C >> "%OutputFile%"
    )
  )
)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question