tempman Posted December 7, 2017 Posted December 7, 2017 Hi, is it possible to sort IP address by PORT? This is my buggy script: expandcollapse popup#include <Array.au3> #cs No sorted --------- 175.164.4.196:80 143.59.44.41:443 62.68.190.92:8000 77.119.25.12:80 101.167.48.241:8080 80.243.169.25:8443 Sorted ------ 77.119.25.12:80 175.164.4.196:80 143.59.44.41:443 62.68.190.92:8000 101.167.48.241:8080 80.243.169.25:8443 #ce Local $aArray[6] = ["175.164.4.196:80", _ "143.59.44.41:443", _ "62.68.190.92:8000", _ "77.119.25.12:80", _ "101.167.48.241:8080", _ "80.243.169.25:8443"] _ArrayDisplay($aArray, "No sorted") _Sort($aArray) _ArrayDisplay($aArray, "Sorted") Func _Sort(ByRef $aArray) _ArrayColInsert($aArray, 1) For $i = 0 To UBound($aArray) - 1 $aArray[$i][1] = StringRegExpReplace($aArray[$i][0], '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{1,4}', "$4$3$2$1") Next _ArraySort($aArray, 0, 0, 0, 1) _ArrayColDelete($aArray, 1) EndFunc ;==>_Sort Thanks!
kylomas Posted December 7, 2017 Posted December 7, 2017 (edited) tempman, This creates a 2d array whereby the first element is the sort argument and the second element is the complete ip address. The sort element is expanded to 4 digits for the sort to work properly... #include <array.au3> Local $aArray[6] = ["175.164.4.196:80", _ "143.59.44.41:443", _ "62.68.190.92:8000", _ "77.119.25.12:80", _ "101.167.48.241:8080", _ "80.243.169.25:8443"] Local $array_that_can_be_sorted[UBound($aArray)][2] For $i = 0 To UBound($aArray) - 1 ;ConsoleWrite($i & @CRLF) $array_that_can_be_sorted[$i][0] = StringFormat('%04i', StringRegExpReplace($aArray[$i], '[^:]+:(.*)', '$1')) $array_that_can_be_sorted[$i][1] = $aArray[$i] Next _ArrayDisplay($array_that_can_be_sorted) _ArraySort($array_that_can_be_sorted) _ArrayDisplay($array_that_can_be_sorted) kylomas Edited December 7, 2017 by kylomas tempman 1 Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
kylomas Posted December 7, 2017 Posted December 7, 2017 tempman, NP, you were on the right track... Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
tempman Posted December 7, 2017 Author Posted December 7, 2017 But how to save only Col 1 data to txt file? #include <Array.au3> #include <File.au3> Local $aArray[6] = ["175.164.4.196:80", _ "143.59.44.41:443", _ "62.68.190.92:8000", _ "77.119.25.12:80", _ "101.167.48.241:8080", _ "80.243.169.25:8443"] Local $array_that_can_be_sorted[UBound($aArray)][2] For $i = 0 To UBound($aArray) - 1 ;ConsoleWrite($i & @CRLF) $array_that_can_be_sorted[$i][0] = StringFormat('%04i', StringRegExpReplace($aArray[$i], '[^:]+:(.*)', '$1')) $array_that_can_be_sorted[$i][1] = $aArray[$i] Next _ArrayDisplay($array_that_can_be_sorted) _ArraySort($array_that_can_be_sorted) _ArrayDisplay($array_that_can_be_sorted) _ArrayDisplay($array_that_can_be_sorted, "","|1:1") Local $sFilePath = FileOpen(@ScriptDir & "\zzz.txt", 1) _FileWriteFromArray($sFilePath, $array_that_can_be_sorted)
SlackerAl Posted December 7, 2017 Posted December 7, 2017 _ArrayColDelete Delete unwanted column? tempman 1 Problem solving step 1: Write a simple, self-contained, running, replicator of your problem.
tempman Posted December 7, 2017 Author Posted December 7, 2017 For this example it will do the job, but is there any solution where I can choose what column I want to save?
jdelaney Posted December 7, 2017 Posted December 7, 2017 Make your own function, one variable for the array, another for the column...loop through that specific column and do the writes. IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
kylomas Posted December 8, 2017 Posted December 8, 2017 tempman, As jdelaney suggests... #include <Array.au3> #include <File.au3> Local $aArray[6] = ["175.164.4.196:80", _ "143.59.44.41:443", _ "62.68.190.92:8000", _ "77.119.25.12:80", _ "101.167.48.241:8080", _ "80.243.169.25:8443"] Local $array_that_can_be_sorted[UBound($aArray)][2] For $i = 0 To UBound($aArray) - 1 ;ConsoleWrite($i & @CRLF) $array_that_can_be_sorted[$i][0] = StringFormat('%04i', StringRegExpReplace($aArray[$i], '[^:]+:(.*)', '$1')) $array_that_can_be_sorted[$i][1] = $aArray[$i] Next _ArrayDisplay($array_that_can_be_sorted) _ArraySort($array_that_can_be_sorted) _ArrayDisplay($array_that_can_be_sorted) _ArrayDisplay($array_that_can_be_sorted, "", "|1:1") Local $sFilePath = FileOpen(@ScriptDir & "\zzz.txt", 1) ; iterate thru the array outputing whatever column you want in whatever format you want Local $hfl = FileOpen(@ScriptDir & '\zzz.txt', 2), $str = '' For $i = 0 To UBound($array_that_can_be_sorted) - 1 $str &= $array_that_can_be_sorted[$i][1] & ',' ; format col 1 of array for camma delimited write Next FileWrite($hfl, $str) FileClose($hfl) ;_FileWriteFromArray($sFilePath, $array_that_can_be_sorted) kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
tempman Posted December 8, 2017 Author Posted December 8, 2017 Hi, and again, thank you all! I was aware of this kind of solution, but I thought if there is this: _ArrayDisplay($array_that_can_be_sorted, "", "|1:1") Maybe there is something like this: _FileWriteFromArray($sFilePath, $array_that_can_be_sorted, "|1:1") Or I just became lazy?
iamtheky Posted December 8, 2017 Posted December 8, 2017 (edited) close, and I believe @kylomas adds a bonus comma #include <File.au3> Local $aArray[6] = ["175.164.4.196:80", _ "143.59.44.41:443", _ "62.68.190.92:8000", _ "77.119.25.12:80", _ "101.167.48.241:8080", _ "80.243.169.25:8443"] Local $array_that_can_be_sorted[UBound($aArray)][2] For $i = 0 To UBound($aArray) - 1 ;ConsoleWrite($i & @CRLF) $array_that_can_be_sorted[$i][0] = StringFormat('%04i', StringRegExpReplace($aArray[$i], '[^:]+:(.*)', '$1')) $array_that_can_be_sorted[$i][1] = $aArray[$i] Next $column = 1 consolewrite(_ArrayToString($array_that_can_be_sorted , "," , -1 , -1 , "," , $column , $column)) Edited December 8, 2017 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
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