script to extract text from a file and place into another file

cbones used Ask the Experts™
Looking for a script to find a specific word in a file and copy some text after it?


$This is a test - For something - Else

The script would find "$" and copy "$This is a test - For something" leaving out the rest.   Looking for the second "-" as a completion.  It would loop through the file and copy that data wherever it saw the criteria to a new file.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2014

Please post an example file with such changes.  Your description doesn't convey the actual data transformation you want


I attached two files.  A Source file and Destination file.  The second "-" could be used as a mark to copy the data out to a new file.

Thank you
IT / Software Engineering Consultant
Top Expert 2016
Here is a basic BAT approach that does what you described.  If all the lines will always start with a $ then it could be even simpler...

@echo off

set FileIn=in.txt
set FileOut=out.txt

    for /f "tokens=1-2 delims=-" %%A in ('findstr /i /l /b /c:"$"^<"%FileIn%"') do (
        echo %%A-%%B

Open in new window


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial