antmar904 Posted August 15, 2019 Share Posted August 15, 2019 (edited) Hi, I have a txt file with a list of ips about 200 with one ip address on one line. Exp: 1.1.1.1 123.44.41.144 I need to read the text file and get all the ips then right to a new text file a string that contains this text " sourceIP = '$IP from txt file' or destinationIP = '$IP from txt file' and so on. It needs to be a one line string because I am using the output in a AQL statement. My output is not a one line string. #include <Array.au3> #include <File.au3> $IPs = FileReadToArray("C:\Temp\S2S.txt") For $i = 0 to UBound($IPs) -1 FileWrite("C:\Temp\output.txt", "or sourceIP = " & "'" & $IPs[$i] & "'" & " or destinationIP = " & "'" & $IPs[$i] & "'" & " ") Next Edited August 15, 2019 by antmar904 Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted August 15, 2019 Moderators Share Posted August 15, 2019 Perhaps just build your string as you go, and then FileWrite? Or am I misunderstanding you? $aIPs = FileReadToArray("<file>") $sString = "sourceIP = '" & $aIPs[0] & " " For $a = 1 To UBound($aIPs) - 1 If Mod($a, 2) Then $sString &= "or destinationIP = '" & $aIPs[$a] & "' " Else $sString &= "or sourceIP = '" & $aIPs[$a] & "' " EndIf Next ConsoleWrite($sString & @CRLF) "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
mikell Posted August 15, 2019 Share Posted August 15, 2019 You might concatenate to build a string and then write it to the output file $s = "" For $i = 0 to UBound($IPs) -1 $s &= "or sourceIP = " & "'" & $IPs[$i] & "'" & " or destinationIP = " & "'" & $IPs[$i] & "'" & " " Next msgbox(0,"", StringTrimLeft($s, 3)) Link to comment Share on other sites More sharing options...
antmar904 Posted August 15, 2019 Author Share Posted August 15, 2019 @mikell This seems to work. Thanks! @JLogan3o13 What you provided only added the ip address to the string once. I needed each ip in the txt file to to be written for both "sourceIP = and destinationIP =". Thank you for your efforts and help. 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