Sign in to follow this  
Followers 0
steelsking

strip string

6 posts in this topic

hi guys,

with the following log file, how do I extract just the Serial thingy?

598761: May 5 22:33:52: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/4, changed state to up

598762: May 5 22:34:12: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/4, changed state to down

598763: May 5 22:35:12: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/7, changed state to up

598764: May 5 22:35:32: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/7, changed state to down

598765: May 5 22:35:42: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/7, changed state to up

598766: May 5 22:36:12: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/7, changed state to down

598767: May 5 22:39:02: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/0, changed state to up

598768: May 5 22:39:32: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/0, changed state to down

598769: May 5 22:40:12: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/0, changed state to up

598770: May 5 22:40:42: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/0, changed state to down

598771: May 5 22:46:32: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/4, changed state to up

598772: May 5 22:46:52: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/4, changed state to down

598773: May 5 22:49:12: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/4, changed state to up

598774: May 5 22:49:42: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/4, changed state to down

598775: May 5 22:50:52: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/0, changed state to up

598776: May 5 22:50:52: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/5, changed state to up

598777: May 5 22:51:22: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/0, changed state to down

598778: May 5 22:51:22: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/5, changed state to down

598779: May 5 23:00:22: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/6, changed state to up

598780: May 5 23:00:42: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/0, changed state to up

598781: May 5 23:00:52: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/6, changed state to down

598782: May 5 23:01:12: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/0, changed state to down

598783: May 5 23:06:02: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/4, changed state to up

598784: May 5 23:06:32: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/4, changed state to down

598785: May 5 23:07:32: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/4, changed state to up

598786: May 5 23:08:02: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/4, changed state to down

598787: May 5 23:09:34: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/5, changed state to up

598788: May 5 23:10:02: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/5, changed state to down

598789: May 5 23:14:53: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/5, changed state to up

598790: May 5 23:15:23: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/5, changed state to down

598791: May 5 23:15:33: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/6, changed state to up

598792: May 5 23:16:03: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/6, changed state to down

598793: May 5 23:20:13: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/7, changed state to up

598794: May 5 23:20:43: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/7, changed state to down

598795: May 5 23:23:43: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/6, changed state to up

598796: May 5 23:24:13: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/6, changed state to down

598797: May 5 23:34:53: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/7, changed state to up

598798: May 5 23:35:23: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/7, changed state to down

I just the "Serial12/0/7" meaning Serial till the ","

kindly assist. Thanks.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Use a StringRegEx instead of a StringSplit.

This will do the trick.

#include <array.au3>
#include <file.au3>
Global $aFile, $aLinks
Global $n = 0
$LogFile = FileRead("File.txt")
$aLinks = StringRegExp($LogFile,'(?i)(?s)on Interface (.*?),',3)
For $i = 0 To UBound($aLinks) -1 Step 2
  MsgBox(0, "Test", $aLinks[$i])
Next

Just re-name the File.txt to whatever you have this info saved into.

Edited by Damein

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

This code would work:

#include <Array.au3>
Local $tString
$tString &= '598761: May 5 22:33:52: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/4, changed state to up' & @LF
$tString &= '598762: May 5 22:34:12: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/4, changed state to down' & @LF
$tString &= '598763: May 5 22:35:12: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/7, changed state to up' & @LF
$tString &= '598764: May 5 22:35:32: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/7, changed state to down' & @LF
$tString &= '598765: May 5 22:35:42: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/7, changed state to up' & @LF
$tString &= '598766: May 5 22:36:12: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/7, changed state to down' & @LF
$tString &= '598767: May 5 22:39:02: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/0, changed state to up' & @LF
$tString &= '598768: May 5 22:39:32: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/0, changed state to down' & @LF
$tString &= '598769: May 5 22:40:12: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/0, changed state to up' & @LF
$tString &= '598770: May 5 22:40:42: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/0, changed state to down' & @LF
$tString &= '598771: May 5 22:46:32: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/4, changed state to up' & @LF
$tString &= '598772: May 5 22:46:52: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/4, changed state to down' & @LF
$tString &= '598773: May 5 22:49:12: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/4, changed state to up' & @LF
$tString &= '598774: May 5 22:49:42: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/4, changed state to down' & @LF
$tString &= '598775: May 5 22:50:52: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/0, changed state to up' & @LF
$tString &= '598776: May 5 22:50:52: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/5, changed state to up' & @LF
$tString &= '598777: May 5 22:51:22: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/0, changed state to down' & @LF
$tString &= '598778: May 5 22:51:22: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/5, changed state to down' & @LF
$tString &= '598779: May 5 23:00:22: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/6, changed state to up' & @LF
$tString &= '598780: May 5 23:00:42: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/0, changed state to up' & @LF
$tString &= '598781: May 5 23:00:52: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/6, changed state to down' & @LF
$tString &= '598782: May 5 23:01:12: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/0, changed state to down' & @LF
$tString &= '598783: May 5 23:06:02: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/4, changed state to up' & @LF
$tString &= '598784: May 5 23:06:32: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/4, changed state to down' & @LF
$tString &= '598785: May 5 23:07:32: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/4, changed state to up' & @LF
$tString &= '598786: May 5 23:08:02: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/4, changed state to down' & @LF
$tString &= '598787: May 5 23:09:34: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/5, changed state to up' & @LF
$tString &= '598788: May 5 23:10:02: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/5, changed state to down' & @LF
$tString &= '598789: May 5 23:14:53: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/5, changed state to up' & @LF
$tString &= '598790: May 5 23:15:23: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/5, changed state to down' & @LF
$tString &= '598791: May 5 23:15:33: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/6, changed state to up' & @LF
$tString &= '598792: May 5 23:16:03: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/6, changed state to down' & @LF
$tString &= '598793: May 5 23:20:13: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/7, changed state to up' & @LF
$tString &= '598794: May 5 23:20:43: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/7, changed state to down' & @LF
$tString &= '598795: May 5 23:23:43: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/6, changed state to up' & @LF
$tString &= '598796: May 5 23:24:13: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/6, changed state to down' & @LF
$tString &= '598797: May 5 23:34:53: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/7, changed state to up' & @LF
$tString &= '598798: May 5 23:35:23: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/7, changed state to down'

$iFound = StringRegExp($tString, '(?im)(Serial.*),', 3)
If IsArray($iFound) Then _ArrayDisplay($iFound)
Edited by Varian

Share this post


Link to post
Share on other sites

$sStr = StringRegExpReplace(FileRead($LogFile), "(?i).+(serialh?[d/]+).+", "$1")
ClipPut ($sStr)


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Try this on your text file.

#include <String.au3>
#include <array.au3>
Global $File = FileOpen(@ScriptDir & "Test2.txt") ; <<<<  Change this to  your file's name
$Text = FileRead($File)
$Interface = _StringBetween($Text, "Interface ", ",")
_ArrayDisplay($Interface) ; <<<<    for display purposes only.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

wow!!! so many ways to achieve this!

thanks alot guys!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0