atnextc Posted February 14, 2014 Posted February 14, 2014 Hey guys, I have a problem I have run into on a script that was going rather well given the limited amount of scripting / programming knowledge that I have. The issue that I have run into seems to be a catch 22 in that I have 2 files which contain router interface commands for our equipment. I basically need to declare a variable in one for loop, and pass that same variable to either another function or another for loop. What I am getting now is "Subscript used with non-Array variable.:" on $asideinterface for the _bside function I"m basically trying to grab this data from both files. Test.txt would be the A side, and Test2.txt would be the Z side. $asideinterface = _StringBetween ($ainput[$a],"interfaces ", " description") $circuitid = _StringBetween ($ainput[$a],"""Cox;",";C4") $zsiderouter = _StringBetween ($ainput[$a],"C4 ;",";") $zsideinterface = _StringBetween ($ainput[$a],";", ";") <-----I'm trying to grab whats between ; and ; towards the end of the file, but i can't tell it not to use the first instance of what it finds using _StringBetween Sample code posted below. Sample code that can be used for "test.txt" and "test2.txt" listed in code. Test.txt: set interfaces xe-0/0/6 description "Cox;13001.GE10.CHCGILDTJBW.PRVERIXYJAW;C4 CHGOBPRJ02;xe-0/0/0;MR;10GE TO CHGOBPRJ02 #1;" Test2.txt: set interfaces xe-0/0/0 description "Cox;13001.GE10.CHCGILDTJBW.PRVERIXYJAW;C4 PROVBBRJ01;xe-0/0/6;MR;10GE To PROVBBRJ01;" expandcollapse popup#include <file.au3> #include <String.au3> Local $a,$afile, $bfile, $ainput, $binput,$circuitid, $asiderouter, $zsiderouter, $asideinterfaces,$zsideinterfaces $afile = @ScriptDir & "\test.txt" $bfile = @ScriptDir & "\test2.txt" _FileReadToArray($afile,$ainput) _FileReadToArray($bfile,$binput) For $b = 0 To UBound($binput)-1 $zsideinterfaces = _StringBetween ($binput[$b],"interfaces ", " description") $asideinterfaces = _StringBetween ($binput[$b],";", ";") <-----I'm trying to grab whats between ; and ; towards the end of the file, but i can't tell it not to use the first instance of what it finds using _StringBetween if stringinstr($binput[$b],"description") Then filewrite (@ScriptDir & "\bsideinterfaces.txt",$zsideinterfaces[0]& @CRLF) filewrite (@ScriptDir & "\bsideinterfaces.txt",$asideinterfaces[0]& @CRLF) EndIf Next For $a = 0 To UBound($ainput)-1 $asideinterfaces = _StringBetween ($ainput[$a],"interfaces ", " description") $zsideinterfaces = _StringBetween ($ainput[$a],";", ";;") if stringinstr($ainput[$a],"description") Then filewrite (@ScriptDir & "\asideinterfaces.txt",$asideinterfaces[0]& @CRLF) filewrite (@ScriptDir & "\asideinterfaces.txt",$zsideinterfaces[0]& @CRLF) EndIf Next _bside() func _bside() For $b = 0 to UBound($binput)-1 $zsideinterfaces = _StringBetween ($binput[$b],"interfaces ", " description") $circuitid = _StringBetween ($binput[$b],"""Cox;",";C4") ;$circuitid = _StringBetween($binput[$b],";", @CRLF) local $asiderouter = _StringBetween ($binput[$b],";C4 ",";") local $asideinterfaces = _StringBetween ($binput[$b],";", ";")<-----I'm trying to grab whats between ; and ; towards the end of the file, but i can't tell it not to use the first instance of what it finds using _StringBetween if stringinstr($binput[$b],"description") Then _FileWriteToLine(@ScriptDir & "\test2.txt", $b, "set interfaces " &$zsideinterfaces[0]& " description ""Cox;"&$circuitid[0]&";C4 "&$asiderouter[0]&";"& $asideinterfaces[0] &";MR;10GE To " & $asiderouter[0] &";""", 1) EndIf Next EndFunc _aside() func _aside() For $a = 1 to UBound($ainput) -1 $asideinterfaces = _StringBetween ($ainput[$a],"interfaces ", " description") Local $circuitid = _StringBetween ($ainput[$a],"""Cox;",";C4") local $zsiderouter = _StringBetween ($ainput[$a],";C4 ",";") local $zsideinterfaces = _StringBetween ($ainput[$a],";", ";MR;10GE") if stringinstr($ainput[$a],"description") Then _FileWriteToLine(@ScriptDir & "\test.txt", $a, "set interfaces " &$asideinterfaces[0]& " description ""Cox;"&$circuitid[0]&";C4 "&$zsiderouter[0]&";"& $zsideinterfaces[0] &";MR;10GE To " & $zsiderouter[0] &";""", 1) EndIf Next EndFunc Please let me know if I need to be more clear I know this is kind of all over the place. Thanks for any help in advance.
JohnOne Posted February 14, 2014 Posted February 14, 2014 $zsideinterfaces = _StringBetween ($ainput[$a],";", ";;") <<<<< typo?? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
atnextc Posted February 14, 2014 Author Posted February 14, 2014 yea typo when i put it in there. its not that way in the actual script.
orbs Posted February 14, 2014 Posted February 14, 2014 the error is typical when you are calling a function that is supposed to return an array - for example, _StringBetween() - but some error has occurred, and the function did not return the array. check @error after calling _StringBetween() Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff
JohnOne Posted February 14, 2014 Posted February 14, 2014 Appears to work for me. Anything added or changed is indicated. expandcollapse popup#include <file.au3> #include <Array.au3> #include <String.au3> Local $a, $afile, $bfile, $ainput, $binput, $circuitid, $asiderouter, $zsiderouter, $asideinterfaces, $zsideinterfaces $afile = @ScriptDir & "\test.txt" $bfile = @ScriptDir & "\test2.txt" _FileReadToArray($afile, $ainput) _ArrayDisplay($ainput);<<<<<<<<<<<<<<<<<<<<<<<<<<<<< _FileReadToArray($bfile, $binput) _ArrayDisplay($ainput);<<<<<<<<<<<<<<<<<<<<<<<<<<<<< For $b = 1 To $binput[0];<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $zsideinterfaces = _StringBetween($binput[$b], "interfaces ", " description") _ArrayDisplay($zsideinterfaces) $asideinterfaces = _StringBetween($binput[$b], ";", ";") ;< - - - - -I'm trying to grab whats between ; and ; towards the end of the file, but i can' t tell it Not To use the first instance of what it finds using _StringBetween _ArrayDisplay($asideinterfaces) If StringInStr($binput[$b], "description") Then FileWrite(@ScriptDir & "\bsideinterfaces.txt", $zsideinterfaces[0] & @CRLF) FileWrite(@ScriptDir & "\bsideinterfaces.txt", $asideinterfaces[0] & @CRLF) EndIf Next For $a = 1 To $ainput[0];<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $asideinterfaces = _StringBetween($ainput[$a], "interfaces ", " description") $zsideinterfaces = _StringBetween($ainput[$a], ";", ";") If StringInStr($ainput[$a], "description") Then FileWrite(@ScriptDir & "\asideinterfaces.txt", $asideinterfaces[0] & @CRLF) FileWrite(@ScriptDir & "\asideinterfaces.txt", $zsideinterfaces[0] & @CRLF) EndIf Next _bside() Func _bside() For $b = 0 To UBound($binput) - 1 $zsideinterfaces = _StringBetween($binput[$b], "interfaces ", " description") $circuitid = _StringBetween($binput[$b], """Cox;", ";C4") ;$circuitid = _StringBetween($binput[$b],";", @CRLF) Local $asiderouter = _StringBetween($binput[$b], ";C4 ", ";") Local $asideinterfaces = _StringBetween($binput[$b], ";", ";") ;< - - - - -I'm trying to grab whats between ; and ; towards the end of the file, but i can' t tell it Not To use the first instance of what it finds using _StringBetween If StringInStr($binput[$b], "description") Then _FileWriteToLine(@ScriptDir & "\test2.txt", $b, "set interfaces " & $zsideinterfaces[0] & " description ""Cox;" & $circuitid[0] & ";C4 " & $asiderouter[0] & ";" & $asideinterfaces[0] & ";MR;10GE To " & $asiderouter[0] & ";""", 1) EndIf Next EndFunc ;==>_bside _aside() Func _aside() For $a = 1 To UBound($ainput) - 1 $asideinterfaces = _StringBetween($ainput[$a], "interfaces ", " description") Local $circuitid = _StringBetween($ainput[$a], """Cox;", ";C4") Local $zsiderouter = _StringBetween($ainput[$a], ";C4 ", ";") Local $zsideinterfaces = _StringBetween($ainput[$a], ";", ";MR;10GE") If StringInStr($ainput[$a], "description") Then _FileWriteToLine(@ScriptDir & "\test.txt", $a, "set interfaces " & $asideinterfaces[0] & " description ""Cox;" & $circuitid[0] & ";C4 " & $zsiderouter[0] & ";" & $zsideinterfaces[0] & ";MR;10GE To " & $zsiderouter[0] & ";""", 1) EndIf Next EndFunc ;==>_aside AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
atnextc Posted February 14, 2014 Author Posted February 14, 2014 (edited) thanks JohnOne For the reply. While it is not erroring, its still not grabbing the correct information for the Zside interface. I believe i've done what you posted above before while trying to get this to work, thinking heck yea finally figured it out. the only thing i'm interested in getting that i can't seem to get properly is in bold below. set interfaces xe-0/0/6 description "Cox;13001.GE10.CHCGILDTJBW.PRVERIXYJAW;C4 CHGOBPRJ02;xe-0/0/0;MR;10GE TO CHGOBPRJ02;" What the script above does is grabs everything between ; and ; and writes that back into the file resulting in the following:set interfaces xe-0/0/6 description "Cox;13001.GE10.CHCGILDTJBW.PRVERIXYJAW;C4 CHGOBPRJ02;13001.GE10.CHCGILDTJBW.PRVERIXYJAW;C4 CHGOBPRJ02;xe-0/0/0;MR;10GE TO CHGOBPRJ02;" what this is essentially doing is copying the "circuitID" field and the "zsiderouter" field 2 times and pasting it back in the file. I've also tried doing an if stringinstr = the above syntax to basically remove the dupes but it didn't resolve the issue. Any ideas are more than welcome i've been working like 20+ hours just trying to get this one stupid part right, and I can't move on with the script unfortunately until this is correct. Edited February 14, 2014 by atnextc Fixed font size
Moderators Melba23 Posted February 14, 2014 Moderators Posted February 14, 2014 atnextc,Please use standard font size when you post - making it as small as it was will not help you, as many people will not even bother to read it. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
atnextc Posted February 14, 2014 Author Posted February 14, 2014 Melba23 thanks, didn't even notice that. Not sure how that happened
mikell Posted February 14, 2014 Posted February 14, 2014 (edited) Can't this be done with just a small regex ? ; before $str = 'set interfaces xe-0/0/6 description "Cox;13001.GE10.CHCGILDTJBW.PRVERIXYJAW;C4 CHGOBPRJ02;xe-0/0/0;MR;10GE TO CHGOBPRJ02;"' $res = StringRegExpReplace($str, '(.+?);(.+?;.+?);(.+)', "$1;$2;$2;$3") Msgbox(0,"", $res) ; after ; set interfaces xe-0/0/6 description "Cox;13001.GE10.CHCGILDTJBW.PRVERIXYJAW;C4 CHGOBPRJ02;13001.GE10.CHCGILDTJBW.PRVERIXYJAW;C4 CHGOBPRJ02;xe-0/0/0;MR;10GE TO CHGOBPRJ02;" Edited February 14, 2014 by mikell
atnextc Posted February 17, 2014 Author Posted February 17, 2014 mikell, thanks, what i'm looking for is to parse out only the second interface that is listed in the description which in the sample example provided is xe-0/0/0. I"m not familiar with regex. I imagine there is a way to grab that out using them though.
atnextc Posted February 17, 2014 Author Posted February 17, 2014 well probably not the best method. I was able to do what I needed using: $str = 'set interfaces xe-0/0/6 description "Cox;13001.GE10.CHCGILDTJBW.PRVERIXYJAW;C4 CHGOBPRJ02;xe-0/0/0;MR;10GE TO CHGOBPRJ02;"' $res = StringSplit($str,";",2) Msgbox(0,"", $res[3])
mikell Posted February 17, 2014 Posted February 17, 2014 Oh yes, on reading your previous post I thought that the purpose was to get the whole 2nd string by modifying the first one But to grab 'xe-0/0/0' only StringSplit is obviously the best way
atnextc Posted February 20, 2014 Author Posted February 20, 2014 So ran into another issue semi related. Basically i'm reading a file into an array in 1 function, and its running a certain number of times, lets say 6. The array has lets say 10 items in it. Then I'm reading that same file into another array in another function later on in the script. How can I "pick up" at value 7 and have it loop the remaining 3 times in this example till it reaches the end of the array. I can provide examples of what i've tried if need be. Thanks
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now