Mein Vorschlag:
[autoit];*******************************************************************************************************************************
#include <File.au3>
$srcfile = @ScriptDir & "\services"
$replaceString = "sapmsFC1" & @TAB & "3680/tcp" & @TAB & "# SAP System Messaging Service Port"
$searchString = "sapmsFC1"
Search_And_Replace($srcfile, $searchString, $replaceString, 1)
[/autoit][autoit][/autoit][autoit]Func Search_And_Replace($s_file, $s_searchString, $s_replaceString, $b_DeleteDuplicates)
; $s_file = filename
; $s_searchString = string to search in file
; $s_replaceString = string to replace the searched string in file
; $b_DeleteDuplicates = flag, value 0=no or 1=yes, to deletes all duplicate lines of the search string or not,
Local $stringCount
$sfile = FileOpen($s_file, 0)
For $i = 1 To _FileCountLines($s_file)
$readline = FileReadLine($sfile, $i)
If StringInStr($readline, $s_searchString, 2) Then
$stringCount += 1
;MsgBox(0, "String found!", "The String " & $s_searchString & " is found in line: " & $i)
If $stringCount > 1 Then
_FileWriteToLine($s_file, $i, "", 1)
Else
_FileWriteToLine($s_file, $i, $s_replaceString, 1)
EndIf
EndIf
Next
FileClose($sfile)
EndFunc ;==>Search_And_Replace
;*******************************************************************************************************************************;
Habs getestet, es ist kürzer und funktioniert!
Gruß Ashpool