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
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?
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
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:
Summary: I want to use a batch file to copy part of a file to another file. Specifically from html to html. The section i want to copy is surrounded by comment <!--menu-->. I want to copy from one and pu...
Summary: I have read some of the posts on this forum, so I know there are some batch file masters around. I look forward to seeing what kind of solutions to this 'puzzle' they can come up with. I am writing a...
Summary: I would like to write a batch file that would copy files from one directory to another but not overwrite OR abbort if a file already exists with that name. If a file already exists, i would like it to...