How to retrieve a particular content ina file ina directory

March 30, 2012 at 02:35:39
Specs: Windows 7
How do i retrieve text including two strings that may appear any number of times in a file ina directory, i have to search all the files and i have to get the content from all the files in the directory.
For example : college students
teenage
youth
end
college
staff
end
college students
toppers
rankers
end

I want only the lines between college students and end including them i.e., eight lines should get copied to a new text file. I want all the files to be searched for this condition and the suitable content from all the files should be copied to a new file. I want the whole commands in a script to be executed, i am a java programmer, if the user selects the button i will make the script to run and i can get the file to be download with all the content from all the directories.


See More: How to retrieve a particular content ina file ina directory

Report •


#1
July 1, 2012 at 23:09:32
try this, not tested:

@echo off & setlocal enabledelayedexpansion
set flag=nul
for /f %%x in ('dir /b *.txt') do (
for /f "tokens=*" %%a in (%%x) do (
if /i "%%a" equ "college students" (
set flag=test
) else (
if /i "%%a" equ "end" set flag=nul
)
>> !flag! echo %%a
)
)
:end

If response, I'll be happy to work on fine-tuning/debugging. Otherwise, good luck.


Report •

#2
July 5, 2012 at 14:31:32
*cough* *cough* Homework.....I swear i have seen this before....

:: mike


Report •
Related Solutions


Ask Question