willywill Posted October 15, 2009 Posted October 15, 2009 Hi all, I have a text file that has an array of IP addresses followed by the hostnames, like so: 10.20.0.1 ACB-HOST01 10.20.0.2 ACB-HOST02 10.20.0.3 ACB-HOST03 My script can search and locate the IP address, but I need to copy only the hostname to the clipboard, so I can rename the computer hostname and description. How can I trim the array, so that only the hostname is copied to the clipboard? Thanks!
rliiack Posted October 15, 2009 Posted October 15, 2009 Use a 2D array. $array[0][0]=10.20.0.1 $array[0][1]=10.20.0.2 $array[0][2]=10.20.0.3 $array[1][0]=ACB-HOST01 $array[1][1]=ACB-HOST02 $array[1][2]=ACB-HOST03 My Projects:Smart Icons
PsaltyDS Posted October 15, 2009 Posted October 15, 2009 Hi all, I have a text file that has an array of IP addresses followed by the hostnames, like so: 10.20.0.1 ACB-HOST01 10.20.0.2 ACB-HOST02 10.20.0.3 ACB-HOST03 My script can search and locate the IP address, but I need to copy only the hostname to the clipboard, so I can rename the computer hostname and description. How can I trim the array, so that only the hostname is copied to the clipboard? Thanks! Many ways to skin that cat. Here's one: #include <Array.au3> ; Only for _ArrayDisplay() Global $avTest[3] = ["10.20.0.1 ACB-HOST01", _ "10.20.0.2 ACB-HOST02", _ "10.20.0.3 ACB-HOST03"] _ArrayDisplay($avTest, "Before") For $n = 0 to UBound($avTest) - 1 $avTest[$n] = StringTrimLeft($avTest[$n], StringInStr($avTest[$n], " ")) Next _ArrayDisplay($avTest, "After") Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
willywill Posted October 15, 2009 Author Posted October 15, 2009 Getting there. my only problem is that I don't want to define them in the script directly for reasons that the IP list will change over time. Here is what I have: $file = FileOpen("C:\dhcp\list.txt", 0) $IPAddress = String(@IPAddress1) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) Select Case @error = -1 MsgBox (0, "Search Result", "End Of File was met") ExitLoop Case StringInStr($line, @IPAddress1) MsgBox (0, "Search Result", $line) ExitLoop EndSelect WEnd FileClose($file) This works to a point of displaying the entire line that matches the IP address. Now I need to trim the fat to get to the hostname.
boogieoompa Posted October 15, 2009 Posted October 15, 2009 Not meaning to oversimplify things but would StringSplit with a space delimter be super easy?
willywill Posted October 15, 2009 Author Posted October 15, 2009 Simplifying is actually a very good idea. I'm a noob, so I'm learning it as I go. StringSplit with a comma delimiter would probably work. Haven't tried it though.
willywill Posted October 16, 2009 Author Posted October 16, 2009 Something like: $stdin = FileOpen("C:\dhcp\list.csv",0) $stdout = FileOpen("C:\dhcp\listout.csv",2) $host = String(@IPAddress1) while 1 $line = FileReadLine($stdin) if @error = -1 then ExitLoop if StringInStr($line,$host) Then $split = StringSplit($line, '\,', 0) FileWriteLine($stdout,$split[2]) MsgBox(0,"Found",$host & " found:" & @crlf & $line & @CRLF & "result has been added to results.csv") EndIf WEnd
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