Deleting blank lines in a text file

Hi,

I'm trying to modify the logfile.txt generated by eggplant at the end of the execution. In the logfile, i want to delete the entries with "click", "tap" and "imagefound" actions. Below is the code:

Code:
--I have placed the logfile.txt in my desktop at the moment
put file "C:\Users\320340\Desktop\LogFile.txt" into inData
repeat with each line x of inData
	put x into tempData
	replace every occurrence of tab in x with " ~ "
	if x contains " ~ click ~ " then
		delete tempData in inData
	else if x contains " ~ tap ~ " then
		delete tempData in inData
	else if x contains " ~ imagefound ~ " then
		delete tempData in inData
	end if
end repeat
put inData into file "C:\Users\320340\Desktop\NewLogFile.txt"

With this code, i'm able to generate the desired output logfile but it comes along with empty blank lines inbetween as a result of the line deletions. Tried different ways to remove these blank lines as per instructions in the different posts in the forum. However, I'm yet to reach a resolution.

Can you please help with this. Thanks.

Comments

  • I dont know if you need that date later on but you could change the global setting for "The ScriptLogging"

    On: Log, LogWarning, and LogError commands, and all interactions with the SUT are recorded.
    Off: Only Log, LogWarning, and LogError commands are recorded..
    Minimal: Only LogWarning and LogError commands are recorded.
    Silent: Nothing is recorded in the Log file. (Warnings and errors are still counted.)
    repeat with each line of file "C:\Users\320340\Desktop\LogFile.txt"
    	if it does not contain "click" and it does not contain "tap" and it does not contain "image found" then put it & return after file "C:\Users\320340\Desktop\NewLogFile.txt"
    end repeat
    
  • SenseTalkDougSenseTalkDoug ForumAdmin admin
    Joost's suggestion to use the ScriptLogging property to limit what goes into the log in the first place is an excellent one if it gives you what you want.

    As for the task of deleting specific lines from text, here's another approach that works well, using SenseTalk's ability to iterate "by reference" :
    put file "C:\Users\320340\Desktop\LogFile.txt" into inData 
    
    repeat with each line x of inData by reference
    	if item 2 delimited by tab of x is in ("click", "tap", "imageFound") then delete x
    end repeat
    
    put inData into file "C:\Users\320340\Desktop\NewLogFile.txt"
    
    Using "repeat … by reference" causes x (in this case) to be a reference to each line, one at a time. When the delete command is used to delete something that is a reference, it deletes the thing that is referred to. In this example, "delete x" will delete an entire line of the source value.

    I explicitly asked for "item 2 delimited by tab" of the log line because the second item on each line of an eggPlant log file is the command name. This prevents accidentally deleting lines that, for example, might happen to have "click" or "tab" somewhere else on the line. Testing whether the command is in a list of values is a convenient shortcut to test for any of several values in a single operation.

    I hope this is helpful!
  • Thank you Joost & Doug.

    Tried & they worked so well. :)

    Regards.
Sign In or Register to comment.