Jump to content

How to get some text lines from text file by batch?


Recommended Posts

Hi to all.

When I run this command

bcdedit /enum all /v > C:\List.txt.

 

List.txt

...Windows Memory Tester---------------------identifier              {b2721d73-1db4-4c62-bf78-c548a880142d}device                  partition=C:path                    \boot\memtest.exedescription             Windows Memory Diagnosticlocale                  en-USinherit                 {7ea2e1ac-2e61-4728-aaa3-896d9d0a9f0e}badmemoryaccess         YesReal-mode Boot Sector---------------------identifier              {57b67fd0-dbb6-11e3-9719-9cb70d9fba21}description             Grub4DOS...

But there are so many information which I need. I just wan to get some lines below

Real-mode Boot Sector---------------------identifier              {57b67fd0-dbb6-11e3-9719-9cb70d9fba21}description             Grub4DOS

I want creat batch file to do this. Is it impossible?

Can anybody help me? Thanks

 

Link to comment
Share on other sites


Is it impossible?

No.

 

I want creat batch file to do this. Is it impossible?

Can anybody help me?

Yes.

Learn about FOR /F with tokens and delims:

http://www.robvanderwoude.com/ntfor.php

http://www.robvanderwoude.com/ntfortokens.php

 

You don't really need a temporary file.

Namely:

@ECHO OFFSETLOCAL ENABLEEXTENSIONSFOR /F "tokens=1,2 delims= " %%A IN ('bcdedit /enum all /v') DO (IF %%A.==identifier. SET %%A=%%BIF %%A.==description. SET %%A=%%BIF /I %%B.==grub4dos. GOTO :out):outSET identifierSET descriptionPAUSE

If you really want to create the text file, replace the FOR line with:

bcdedit /enum all /v>C:\List.txtFOR /F "tokens=1,2 delims= " %%A IN (C:\List.txt) DO (

jaclaz

Link to comment
Share on other sites

Hi, Jaclaz

I have a question. If menu boot contain Whitespace character, How can I edit your command to get some text which I want. i.e Menu boot is "Grub For Dos". I tried 

IF /I %%B.=="grub for dos". GOTO :out

but It's not working.

Thanks :)

Edited by congnt92
Link to comment
Share on other sites

Sure it is not.

"%%B" in that case would be only "grub" as you have delims set to [sPACE] and tokens set to 1 and 2.

Try with tokens=1,* <- the idea of giving you a reference is that you study the syntax, so that you can make changes yourself, but not "random" ones.

Also you need quotes on both sides, like

IF /I "%%B"=="grub for dos" GOTO :out

jaclaz

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...