Search the Community
Showing results for tags 'array filereadarray loops'.
-
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;" #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.