Select multiple lines

December 1, 2009 at 13:08:19
Specs: Windows XP
Hi
I am trying to retrieve 2 seperate lines from multiple text files in a directory and post the result to a single file but am having trouble concatinating the results. The text files all have different names but their internal fomat is basicly the same, as follows:

Status: OK
Something on line 2
TestName: Test 1

I need to get the status and testname lines and send them to a single file so that I create a master test result file but i cant seem to get both lines into a file in a manner that is usefull. Current script I'm using is:

Type C:\SOAPTesting\*.txt | FindStr "Status: OK";"Status: FAILED";"TestName: " >> C:\SOAPTesting\Results.txt

As you can see there are two types of status and multiple test names that I need. Any help would be greatly appreciated.

Thanks


See More: Select multiple lines

Report •


#1
December 1, 2009 at 13:31:30
@echo off
pushd C:\SOAPTesting
type nul > C:\SOAPTesting\Results.txt
for %%j in (*.txt) do (
  type %%j | find "Status:"
  type %%j | find "TestName:"
) >> C:\SOAPTesting\Results.txt
 popd
:: End_Of_Batch


Report •

#2
December 1, 2009 at 14:28:49
Thanks for the quick reply.
This has given me the required output but the result is being repeated within the file?

Status: OK
TestStep: CancelPnr - Cancel1
Status: OK
TestStep: GetFares
Status: OK
TestStep: GetProperties from GetFares
Status: OK
TestStep: HoldFlightOptions - HoldRequest
Status: OK
TestStep: Property Transfer to Cancel
Status: OK
TestStep: Property Transfer to Hold
Status: OK
Status: OK
Status: OK
Status: OK
Status: OK
Status: OK
TestStep: CancelPnr - Cancel1
TestStep: GetFares
TestStep: GetProperties from GetFares
TestStep: HoldFlightOptions - HoldRequest
TestStep: Property Transfer to Cancel
TestStep: Property Transfer to Hold

I had to modify slightly to get the directories right but dont think I did anything that should alter excecution?

@echo off
pushd C:\Toby\SOAPTesting\testresult
type nul > C:\Toby\SOAPTesting\testresult\Results.txt
for %%j in (*.txt) do (
type %%j | find "Status:"
type %%j | find "TestStep:"
) >> C:\Toby\SOAPTesting\testresult\Results.txt
popd
:: End_Of_Batch

I'm new to batch script and am trying to learn but cant figure out why this is seperating and repeating the result below the first set?

Thanks again.


Report •

#3
December 1, 2009 at 14:39:04
Sorry, my mistake, try again with the following modified version

@echo off
pushd C:\Toby\SOAPTesting\testresult
type nul > C:\Toby\SOAPTesting\testresult\Results.tmp
for %%j in (*.txt) do (
  type %%j | find "Status:"
  type %%j | find "TestStep:"
) >> C:\Toby\SOAPTesting\testresult\Results.tmp
ren C:\Toby\SOAPTesting\testresult\Results.tmp *.txt
popd
:: End_Of_Batch


Report •

Related Solutions

#4
December 1, 2009 at 14:56:49
Perfect, Thank you.

I can understnd most of the format but the %%J has me baffled - can you explain its use for me?

Thanks

If you chase two rabbits, both will get away.


Report •

#5
December 2, 2009 at 01:46:04
%%j (beware %%J is not the same as this is one of the rare cases Windows is case sensitive) is an Internal Variable to be used when you code a For loop.

Internal variables may be %%a up to %%Z and when coded directly at the prompt must be prefixed by just ONE %. To know more about For statements type For /? at prompt (the same for any other command you want to investigate - sometime you have to type command /? | more to control the scrolling).

Other types of variables are External and Environmental.

External variables are %1 up to %9 and are associated to command tail parameters (e.g. mybatch parm1 parm2 ...).

Environmental variables are defined by the Set command or by the operating system as %time%.

Variables are the root to code adaptative and really useful batch scripts.


Report •


Ask Question