?
Solved

cut and paste line to new text file

Posted on 2007-03-30
4
Medium Priority
?
228 Views
Last Modified: 2010-04-16
I need to search for a word in a text file then cut and paste that line and any line after until either another word occurs or end of the file into a new text file.

So if looking for the word Production it would cut that and any line until it hit the word Staging or the end of the file:
blah
blah
blah
Production
blah
blah
blah
Staging
blah
blah
Production
blah

So the new text file would have:
Production
blah
blah
blah
Production
blah

And the old file would have:
blah
blah
blah
Staging
blah
blah
0
Comment
Question by:whargra
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 43

Accepted Solution

by:
Steve Knight earned 2000 total points
ID: 18823902
Try this... untested at the moment, sorry so post back any issues.

Steve

@echo off
set source=c:\yourfile.txt
set first=c:\file1.txt
set second=c:\file2.txt
set lookfor1=Staging
set lookfor2=Production
set currentfile=%first%
for /f "tokens=*" %%a in (%source%) do call :process %%a
goto end

:process
set line1=%*
REM Redirect output to second file now.
if "%line1%"=="%lookfor1%" set currentfile=%second%
REM Ignore anything after second word
if "%line1%"=="%lookfor2%" set currentfile=nul
echo %line1%>>%currentfile%
:end
0
 

Author Comment

by:whargra
ID: 18835917
It does not cut and paste the entire line so trying to figure out why.
0
 

Author Comment

by:whargra
ID: 18836792
Data issue. So have that done.

I would like to add one more thing to this, so I will open a new question. Thanks for the help.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 18839612
No problem, not here much at the mo. so someone else will probably pick it up but will keep an eye out.
Steve
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question