Hi,
I'm new in batch commands and need some help.
Let's say I have a file (test.txt) which contain these lines.
Subject: test test
To: 6597712345@sgw.abc.com
Message-ID: <OF2BFE240E.DD9201BC-ON48257607.0033BBC9-48257607.0033DD71@abc.com>
I need to capture some words from the file starting with 'To: ' and 'Subject: ' however I need to delete the @sgw.abc.com and also Subject:
So the output of the new file will be something like this.
To: 6597712345
<empty line here>
test test
The number 65**** is always the same length, which is 10 numbers.
Appreciate if any of you can help.
help to capture some words from file
Moderator: DosItHelp
-
- Posts: 319
- Joined: 12 May 2006 01:13
you can use vbscript
save as myscript.vbs and on command line
Code: Select all
Set objFS = CreateObject("Scripting.FileSystemObject")
strFile = "c:\test\file.txt"
Set objFile = objFS.OpenTextFile(strFile)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
If InStr(strLine,"To:") > 0 Then
s = Split(strLine ,"@")
strTo = s(0)
End If
If InStr(strLine,"Subject:") > 0 Then
s = Split(strLine,":")
strSubject = s(1)
End If
Loop
objFile.Close
WScript.Echo strTo
WScript.Echo
WScript.Echo strSubject
save as myscript.vbs and on command line
Code: Select all
C:\test>cscript /nologo myscript.vbs
To: 6597712345
test test