Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Batch file to extract certain data
Name: jasdjensen Date: April 13, 2008 at 12:38:00 Pacific OS: Win XP/2003 CPU/Ram: Any Product: Any
Comment:
I'd like help creating a batch file that will search a log file for certain sections of text and export them to a log file.
example log file: blah blah blah Startingword This is the sentence I want to grab. Endingword blah blah blah
output: This is the sentence I want to grab.
So would want to be able to set the key starting and ending strings and then have it grab any information in the middle and output it to a file.
Name: ghostdog Date: April 13, 2008 at 21:29:40 Pacific
Reply:
If you are not comfortable still, you can use vbscript
Set objFS=CreateObject("Scripting.FileSystemObject") strMyFile = "c:\test\test.txt" Set objFile = objFS.OpenTextFile(strMyFile) Do Until objFile.AtEndOfLine strLine = objFile.ReadLine startPos = InStr(1,strLine,"Startingword") If startPos > 0 Then strLine = Mid(strLine,startPos+len("Startingword")) endPos = InStr(startPos,strLine,"##") strLine = Mid(strLine,1,endPos-1) WScript.Echo strLine End If Loop
0
Response Number 6
Name: jasdjensen Date: April 13, 2008 at 21:33:03 Pacific
Reply:
It's still not working.
Maybe I'm not being clear and that's what the problem is.
Example log: blah blah 4/10/07 07:50 Rip - blah blah really long sentence more blah blah more stuff ## 4/11/07 10:00 blah blah
output sent to file should be:
4/10/07 07:50 Rip - blah blah really long sentence more blah blah more stuff ##
0
Response Number 7
Name: ghostdog Date: April 13, 2008 at 23:37:21 Pacific
Reply:
try this
/Rip/,/\#\#$/{ print $0 }
0
Response Number 8
Name: jasdjensen Date: April 14, 2008 at 13:32:48 Pacific
Reply:
ok.. the solution below works:
/Rip/,/\#\#$/{ print $0 }
Its what I needed. Thanks! I really appreciate it.
Summary: Hi, I have a txt file that contains data in the following format: 1200-1678,,1,C1356 1000-0076,,1,C1357 1000-0051,,1,C1358 1000-6848,,1,C1500 1000-6848,,1,C1501 1000-6848,,1,C1502 1000-6848,,1,C1504 1...
Summary: Hi Reno, wow, it seems you guys really eat and sleep with batch files! lol. I just woke up over here so I missed your replies but thank you for replying. =) In regards to the second part... that is...
Summary: I have an ini file that I would like to extract a value and pass that value through a condition statement to change value if doesn't exit. Does anyone know how to create a batch file to accomplish thi...