Computing.Net > Forums > Programming > Batch File: Copy part of a text to a new file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

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

Reply to Message Icon

Name: aknu
Date: July 22, 2009 at 04:08:47 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: dtech10
Date: July 22, 2009 at 14:46:19 Pacific
Reply:

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
)


0

Response Number 2
Name: ghostdog
Date: July 22, 2009 at 17:22:30 Pacific
Reply:

you can see herefor examples using vbscript

GNU win32 packages | Gawk


0

Response Number 3
Name: aknu
Date: July 23, 2009 at 05:18:28 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


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

copying part of a file to another www.computing.net/answers/programming/copying-part-of-a-file-to-another/18680.html

Batch Extracting part of a string www.computing.net/answers/programming/batch-extracting-part-of-a-string/15641.html

batch file copy without overwrite www.computing.net/answers/programming/batch-file-copy-without-overwrite/12885.html