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?

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.
cbonesAsked:
Who is Participating?
 
Bill PrewCommented:
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
0
 
aikimarkCommented:
Please post an example file with such changes.  Your description doesn't convey the actual data transformation you want
0
 
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
C--Sample-SourceFile.txt
C--Sample-DestinationFile.txt
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.