Solved

Remove extra line in Text file using Autoit

Posted on 2014-04-08
5
1,593 Views
Last Modified: 2014-04-09
I using the Autoit program to create my own program. I have been trying to figure out how how to remove a blank line in a text file. We have a program that outputs a text file. The problem is that it adds a blank line at the end of the file.

when I use the command _FileCountLines
it comes back and says there is 10 lines but when you open the text file you can click on the 11th line. The problem with that is that the company we are uploading this file to says we have to remove that blank line.
0
Comment
Question by:AccordJ35
  • 2
  • 2
5 Comments
 
LVL 9

Expert Comment

by:dustock
ID: 39986329
What command are you using the write the lines?
0
 

Author Comment

by:AccordJ35
ID: 39986410
The program uses a sql store procedure to create the .txt file. It just has a blank line at the end. Trying to figure out how to get rid of it.
0
 
LVL 9

Expert Comment

by:dustock
ID: 39987216
It's been awhile since I last used AutoIT, but I think you should try StringReplace to remove the last line.

Something like:

yourstring = StringReplace(yourstring, @CRLF, '', -1)

If I remember correctly the -1 will remove the last occurrence of what ver you are trying to replace.  You may also want to search for just @CR or @LF if @CRLF doesn't work.  Also you may have to mix functions like StringReplace(StringRight(yourstring, 1), @CRLF, '') but I can't be sure since I am not near a PC to try.
0
 
LVL 29

Accepted Solution

by:
matrixnz earned 500 total points
ID: 39988344
Here are two examples:
1. Using an Array
2. Using StringStripWs

Cheers

#include <File.au3>

Global $hFILENAME = 'Original.txt'
Global $hFILETEMP = 'Updated.txt'

FNC_EXAMPLE1()

FNC_EXAMPLE2()

Func FNC_EXAMPLE1()
Local $aFILENAME, $hFILEOPEN, $x
	 _FileReadToArray($hFILENAME, $aFILENAME)
		If @error Then
			MsgBox(64, 'Error', 'Error reading: ' & $hFILENAME)
			Exit
		EndIf
	Global $hFILEOPEN = FileOpen($hFILETEMP, 2)
		If $hFILEOPEN = -1 Then
			MsgBox(64, 'Error', 'Error creating: ' & $hFILETEMP)
			Exit
		EndIf

	For $x = 1 To $aFILENAME[0]
		If $x = $aFILENAME[0] Then
			FileWrite($hFILEOPEN, $aFILENAME[$x])
		Else
			FileWrite($hFILEOPEN, $aFILENAME[$x] & @CRLF)
		EndIf
	Next
	FileClose($hFILEOPEN)
EndFunc

Func FNC_EXAMPLE2()
	Local $vFILENAME, $hFILEOPEN
	$vFILENAME = FileRead($hFILENAME)
		If @error Then
			MsgBox(64, 'Error', 'Error reading: ' & $hFILENAME)
			Exit
		EndIf
	$hFILEOPEN = FileOpen($hFILETEMP, 2)
		If $hFILEOPEN = -1 Then
			MsgBox(64, 'Error', 'Error creating: ' & $hFILETEMP)
			Exit
		EndIf
	$vFILENAME = StringStripWS($vFILENAME, 2)
	FileWrite($hFILEOPEN, $vFILENAME)
EndFunc

Open in new window

0
 

Author Closing Comment

by:AccordJ35
ID: 39988686
Thanks Function 2 worked for me. :-)
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MaxSpan challenge 9 97
countHi challenge 25 125
numbers ascending pyramid 101 196
Way to decrease size of apk file 9 71
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question