How to filter txt file by string with using batch

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Antediluvian
Posts: 1
Joined: 26 May 2010 05:38

How to filter txt file by string with using batch

#1 Post by Antediluvian » 26 May 2010 06:17

Hello guys
I know this kind of problem will be very easy for you but I am total beginner in batch mode.

The question is how bat file code should look like to generate a new txt file from specific one .

for example .

I have report txt

Image
What I want to have in new file from this one are only lines :

SingleSite_License 3
Intra_CLIENT_License 9

but both SingleSite_License and Intra_Client_License should be taken from 1st found string -other are not necessary. report txt can be different and licenses can be showed in different order .
if it not possible - other solution can be just only Free value will be written in new txt file - f.e 3 and 9 . so the last string in line which contains specific words

thank you for any tips

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: How to filter txt file by string with using batch

#2 Post by !k » 26 May 2010 08:50

Give the report.txt as TEXT

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How to filter txt file by string with using batch

#3 Post by aGerman » 26 May 2010 15:01

Antediluvian,

!k is absolutely right. How should we test any code on an image?! And where did you find any 9? Did you mean the 4 in column "Free"?

In case the values are delimted by spaces or by tabs the following could work:-

Code: Select all

@echo off &setlocal
for /f "tokens=3" %%a in ('findstr /i /c:"SingleSite_License" report.txt') do if not defined SSL set "SSL=%%a"
for /f "tokens=3" %%a in ('findstr /i /c:"Intra_CLIENT_License" report.txt') do if not defined ICL set "ICL=%%a"
(
  echo SingleSite_License %SSL%
  echo Intra_CLIENT_License %ICL%
)>new.txt


Regards
aGerman

Post Reply