Solved How to extract specific lines from a text file to use in bat

November 6, 2013 at 12:04:22
Specs: Windows 7
Hello all

I have a little dilemma

I would like to know if it is possible to extract specific lines from a text file to use the line within a batch file.

I know that the line below will set the variable = to the given string but I dont know how to extract specific lines from the given string.

example
set /P test=c:\myfiles.txt


See More: How to extract specific lines from a text file to use in bat

Report •


#1
November 6, 2013 at 13:03:05
can you post the example text file, and what line you need?

::mike


Report •

#2
November 6, 2013 at 17:56:47
Thanks Mike

Lets say that my filename is myfile.txt for example and below is what i want to extract

::Beginning

[SRC1]
1. Despath = C:\Results\

[SRC2]
2. dmzfolder = Resultpickup/ED1

[SRC3]
3. doing = mput "*.tst"

[SRC4]
4. done = exit

[SRC5]
5. filepattern = *.hl7

[SRC6]
6. local = lcd orders

[SRC7]
7. orderextension = *tst


::End


I want to extract everything after the equal signs and use it in a batch file example test.bat


Report •

#3
November 7, 2013 at 13:59:14
✔ Best Answer
I don't think the "set /P" method will work here, since it only picks up the first line of the file (and, you forgot the <). I would use "Find", like this:
:: begin
@echo off & setlocal
set c=0
for %%a in (despath dmzfolder doing done filepattern local orderextension) do (
for /f (tokens=4) %%b in ('find /i "%%a ="^<myfile.txt') do (
set /a c+=1
echo !c! %%b
)
)
:: not tested

message edited by nbrane


Report •
Related Solutions


Ask Question