ScriptCrafter Posted March 13, 2007 Share Posted March 13, 2007 This may seem like a very n00b script like question, but I am stuck!!! I want to be able to read a file, and for every line that begins with "[[", I want that line stored to a variable Is this even possible? Any help is much appreciated... Thanks -ScriptCrafter Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 13, 2007 Moderators Share Posted March 13, 2007 This may seem like a very n00b script like question, but I am stuck!!! I want to be able to read a file, and for every line that begins with "[[", I want that line stored to a variable Is this even possible? Any help is much appreciated... Thanks -ScriptCrafter_FileReadToArray() + For/Next + Condition Statement + StringLeft(array, 2) = '[[' + Condition. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Misha Posted March 13, 2007 Share Posted March 13, 2007 I would usedim $arraythingy[_FileCountLines(file..)] For i = 1 to _FileCountLines + if StringLeft(ReadFileLine(etc),2 = '[[' then $arraythingy = readfileline(etc) since he did ask to add to a variable...better make 1 array Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 13, 2007 Moderators Share Posted March 13, 2007 better make 1 arrayI gave a foundation not a complete solution... But your statement isn't even a qualifying statement, the OP didn't ask for it to be in an array. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
ScriptCrafter Posted March 13, 2007 Author Share Posted March 13, 2007 (edited) Thanks for the pointers, I have started working with your ideas, but still get an error message :-) DIM $ARRAY[_FileCountLines($FILE)] FOR $I = 1 to _FileCountLines + IF StringLeft(ReadFileLine(etc),2 = "[[" THEN $ARRAY[0] = $HOST1 $ARRAY[1] = $HOST2 $ARRAY[3] = $HOST4 Doesnt seem to keep the content of that line in the file stored as the $HOST Anything wrong here? -ScriptCrafter Edited March 13, 2007 by ScriptCrafter Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 13, 2007 Moderators Share Posted March 13, 2007 (edited) #include <array.au3> Dim $aStore, $aArray _FileReadToArray('FilePath\FileName.Extension', $aArray) For $iCC = 1 To UBound($aArray) - 1 If StringStripWS(StringLeft($aArray[$iCC], 2), 8) = '[[' $aStore &= $aArray[$iCC] & Chr(1) EndIf Next $aStore = StringSplit(StringTrimRight($aStore, 1), Chr(1)) _ArrayDisplay($aStore, '[[') Edited March 13, 2007 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
ScriptCrafter Posted March 13, 2007 Author Share Posted March 13, 2007 Looks good Smoke but instead of displaying the array I need for any line in the file that begins with "[[" stored like this $ARRAY[1] = $HOST1 $ARRAY[2] = $HOST2 $ARRAY[1] should have read the text file and have a value of [[HOSTNAME1]] $ARRAY[2] should have read further into the file and have a value of [[HOSTNAME2]] Thanks ScriptCrafter Link to comment Share on other sites More sharing options...
enaiman Posted March 14, 2007 Share Posted March 14, 2007 DIM $ARRAY[_FileCountLines($FILE)]FOR $I = 1 to _FileCountLines + IF StringLeft(ReadFileLine(etc),2 = "[[" THEN $ARRAY[0] = $HOST1 $ARRAY[1] = $HOST2 $ARRAY[3] = $HOST4 you're making a mistake here "ReadFileLine(etc)" - the syntax is FileReadLine you should do the following: DIM $ARRAY[_FileCountLines($FILE)] $y=0 FOR $I = 1 to _FileCountLines ($FILE) IF StringLeft(FileReadLine($FILE, $i),2) = "[[" THEN $ARRAY[$y] = StringTrimLeft(FileReadLine($FILE, $i),2) $y+=1 EndIf Next The way Sm0ke_N showed you is much easier but ... if you want to do it this way ... it is your choice. SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
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