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

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

Example:

$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.
Comment
Watch Question

Do more with

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

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

Author

Commented:
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
C--Sample-SourceFile.txt
C--Sample-DestinationFile.txt
IT / Software Engineering Consultant
Top Expert 2016
Commented:
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
setlocal

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
    )
)>"%FileOut%"

Open in new window


»bp

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