mentosan Posted July 14, 2008 Share Posted July 14, 2008 I'm using _FileReadToArray ($file, $numbers) to read numbers within a file, but I want only the first 8 numbers (digits) to be read. Which function shall i use for this purpose ? Thx Link to comment Share on other sites More sharing options...
rudi Posted July 14, 2008 Share Posted July 14, 2008 I'm using _FileReadToArray ($file, $numbers) to read numbers within a file, but I want only the first 8 numbers (digits) to be read. Which function shall i use for this purpose ?One digit per line, read just the first 8 lines? Or the first 8 Chars from the 1st line? Or the first occurence of "8 Numbers" in that file?Pls post an example for the file you want to read from (some part of it) and point out, WHAT you want to read from it.Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
mentosan Posted July 14, 2008 Author Share Posted July 14, 2008 The file contains only one line, with an IP address and a port number. So for example the content of file is: 192.123.10.1 4001 I only need the 192.123.10.1 Link to comment Share on other sites More sharing options...
smashly Posted July 14, 2008 Share Posted July 14, 2008 (edited) Hi, many ways you can do what your after, here's one way$sFile = @ScriptDir & "\file1.txt" $FR = FileRead($sFile) ConsoleWrite(StringLeft($FR, StringInStr($FR, " ", 0, -1) - 1) & @LF) file1.txt contained192.123.10.1 4001 Cheers Edited July 14, 2008 by smashly Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 14, 2008 Moderators Share Posted July 14, 2008 $s_text = "192.123.10.1 4001" & @CRLF & "139.321.20.3 4002" $s_ip = StringRegExpReplace($s_text, "(?:.*?)(\d+\.\d+\.\d+\.\d+)(\s*\d+)", "\1") ConsoleWrite($s_ip & @CRLF)As long as the setup is the same with the port, this will get as many IPs that are in the file. 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...
mentosan Posted July 14, 2008 Author Share Posted July 14, 2008 (edited) It is not working. Look, this is my code. I have tried to adapt what you have suggested : #include <file.au3> Dim $ipfile="host.txt" Dim $ipaddress _FileReadToArray ($ipfile, $ipaddress) $file = FileRead ("host.txt") $result = (StringLeft($file, StringInStr($file, " ", 0, -1) - 1) & @LF) ;$result = StringRegExpReplace($file, "(?:.*?)(\d+\.\d+\.\d+\.\d+)(\s*\d+)", "\1") If Ping ($result) Then Run ("telnet -f log_telnet.txt") WinActivate("system32") WinWaitActive("system32") Send ("open " & $ipaddress[1] & "{Enter}") WinWaitActive("Telnet " & $ipaddress[1]) While 1 ControlSend ("Telnet","","","x" & "{Enter}") Wend Else MsgBox(0,"Info", "No ping", 3) Exit EndIf Just to clarify myself: this code should first make a ping to the host ,and if the ping is OK, then it will run the command in the loop (While 1...Wend). Because the host is written in a txt file in this form: <IP address><space><port number>, ping will not work. You can only ping IP address, without port number. That's why I need only IP address string, with no alteration of the rest of the file which will be used later in the script. Edited July 14, 2008 by mentosan Link to comment Share on other sites More sharing options...
rudi Posted July 14, 2008 Share Posted July 14, 2008 Hi. The file contains only one line, with an IP address and a port number. So for example the content of file is: 192.123.10.1 4001 I only need the 192.123.10.1 So the most simple is to split the string at blanks and to take the fist element: #include <array.au3> ; that's for _ArrayDisplay() $handle=fileopen("C:\IPandPORT.txt",0) $MyLine=filereadline($handle) ; read one line = the 1st line fileclose($handle) $SplitArr=StringSplit($MyLine," ") ; split string at each blank, here split into IP and Port _ArrayDisplay($SplitArr) ; just to display ;) $IP=$SplitArr[1] MsgBox(0,"IP Address",$IP) Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
mentosan Posted July 14, 2008 Author Share Posted July 14, 2008 (edited) It is OK now! That's what I was looking for. Great function to split strings! Thanks Rudi ! Cheers ! Edited July 14, 2008 by mentosan 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