How to delete the last line of a text file using the command line?

I have a text file that I import into the access table using the command line. The problem is that this text file has an empty line as the last line. Can someone provide me with a script that deletes my empty line at the end of the file to complete my automation process. I am using the Windows 2000 platform.

+3
source share
3 answers
 sed '$d'

deletes the last line, but is not included in Windows 2000. Get gnu utils to get sed for Windows.

On this site you will find a list of other sed commands for managing files.

+4
source

This works using head

head -n -1 input.txt > output.txt

, , Windows , Cygwin .

+3

There is a script here that removes empty lines from a text file. It is written for Windows 2000.

Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\Test.txt", ForReading)

Do Until objFile.AtEndOfStream
    strLine = objFile.Readline
    strLine = Trim(strLine)
    If Len(strLine) > 0 Then
        strNewContents = strNewContents & strLine & vbCrLf
    End If
Loop

objFile.Close

Set objFile = objFSO.OpenTextFile("C:\Scripts\Test.txt", ForWriting)
objFile.Write strNewContents
objFile.Close
-1
source

Source: https://habr.com/ru/post/1704225/


All Articles