Batch File: Copy part of a text to a new file

July 22, 2009 at 04:08:47
Specs: Windows XP
Hi

I would like to make a batch file which can copy a certain paragraph within an existing textfile into a new file.

I know the starting phrase of the paragraph and I know the phrase immediately after the paragraph.

Does anyone have any suggestions on how to do this?

Kind regards
Anders Knudsen


See More: Batch File: Copy part of a text to a new file

Report •


#1
July 22, 2009 at 14:46:19
Hi Aknu

@echo off
SetLocal EnableDelayedExpansion
type nul > NewFile.txt
set StartText=Start Line of Paragraph
set EndText=End Line which is not Included
set Flag=0
for /f "tokens=* delims=" %%a in ('type XCopy.txt') do (
if /i "%StartText%" EQU "%%a" (set Flag=1)
if /i "%EndText%" EQU "%%a" (set Flag=0)
if !Flag! EQU 1 echo %%a >> NewFile.txt
)


Report •

#2
July 22, 2009 at 17:22:30
you can see herefor examples using vbscript

GNU win32 packages | Gawk


Report •

#3
July 23, 2009 at 05:18:28
Thank you very much for your replies.

dtech10: Your proposal turned out to solve my problem on the whole. However when using "for /f", blank lines are ignored which was a problem for me as I wanted to include the blank lines. I found a way to solve this in the following tip:

http://www.computing.net/howtos/sho...

Regards
Anders Knudsen


Report •

Related Solutions


Ask Question