Jump to content

Read Text file then write to text file in one line


Recommended Posts

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 by antmar904
Link to post
Share on other sites
  • Moderators

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 post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...