{"id":192,"date":"2007-06-30T20:43:16","date_gmt":"2007-06-30T18:43:16","guid":{"rendered":"http:\/\/contoso.se\/blog\/?p=192"},"modified":"2007-06-30T22:59:33","modified_gmt":"2007-06-30T20:59:33","slug":"script-that-returns-multiple-lines","status":"publish","type":"post","link":"https:\/\/contoso.se\/blog\/?p=192","title":{"rendered":"Script that Returns Multiple Lines"},"content":{"rendered":"<p>I saw a couple of questions about a script searching for a word in a logfile and then create a event with the line including the &#8220;word&#8221; but also the two lines before that. This script search for the word &#8220;Warning&#8221; in the file logfile.txt. If found it will generate a local event with the line includning Warning but also the two lines before that.<\/p>\n<p><code>Const ForReading = 1<br \/>\nConst EVENT_WARNING = 2Set objRegEx = CreateObject(\"VBScript.RegExp\")<br \/>\nobjRegEx.Pattern = \"Warning\"<\/p>\n<p>Set objFSO = CreateObject(\"Scripting.FileSystemObject\")<br \/>\nSet objFile = objFSO.OpenTextFile(\"logfile.txt\", ForReading)<\/p>\n<p>strLineNo = 1<\/p>\n<p>Do Until objFile.AtEndOfStream<\/p>\n<p>\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 strSearchString = objFile.ReadLine<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Set colMatches = objRegEx.Execute(strSearchString)<\/p>\n<p>\u00c2\u00a0 \u00c2\u00a0\u00c2\u00a0strCacheC = strCacheB<br \/>\n\u00c2\u00a0\u00c2\u00a0strCacheB = strCacheA<br \/>\n\u00c2\u00a0\u00c2\u00a0strCacheA = strSearchString<\/p>\n<p>\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0<br \/>\n\u00c2\u00a0If colMatches.Count > 0 Then<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 For Each strMatch in colMatches\u00c2\u00a0\u00c2\u00a0<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0<br \/>\n\u00c2\u00a0Set objShell = CreateObject(\"Wscript.Shell\")<br \/>\n\u00c2\u00a0objShell.LogEvent EVENT_WARNING, _<br \/>\n\u00c2\u00a0\"Warning from logfile: \" & vbCr &_<br \/>\n\u00c2\u00a0\"BEGINNING OF LINES\" & vbCr &_<br \/>\n\u00c2\u00a0\"\" & vbCr &_<br \/>\n\u00c2\u00a0 strCacheC & vbCr &_<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 strCacheB & vbCr &_<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 strCacheA & vbCr &_<br \/>\n\u00c2\u00a0\"\" & vbCr &_<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \"END OF LINES.\"<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Next<\/p>\n<p>\u00c2\u00a0End If\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0<\/p>\n<p>strLineNo = strLineNo + 1<\/p>\n<p>Loop<br \/>\nobjFile.Close<\/p>\n<p><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I saw a couple of questions about a script searching for a word in a logfile and then create a event with the line including the &#8220;word&#8221; but also the two lines before that. This script search for the word &#8220;Warning&#8221; in the file logfile.txt. If found it will generate a local event with the &hellip; <a href=\"https:\/\/contoso.se\/blog\/?p=192\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[13],"tags":[],"_links":{"self":[{"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/192"}],"collection":[{"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=192"}],"version-history":[{"count":0,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/192\/revisions"}],"wp:attachment":[{"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=192"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=192"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=192"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}