Solved

Batch File Nested IF

Posted on 2010-09-16
5
1,326 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
  • 3
  • 2
5 Comments
 
LVL 51

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 51

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
 
LVL 9

Author Comment

by:tonydemarco
ID: 33695507
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now