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

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.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Please post an example file with such changes.  Your description doesn't convey the actual data transformation you want
cbonesAuthor 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
Bill PrewIT / Software Engineering ConsultantCommented:
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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.