Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I delete the last line of a text file using the command prompt?

Tags:

cmd

I have a text file that I am importing into access table using command prompt. The problem is that this text file has a blank line as the last line. Can anyone provide me with a script that deletes my blank line at the end of file so as I can finalize my automation process. I am using Windows 2000 platform.


1 Answers

 sed "$d" input.txt > output.txt

deletes the last line, but it's not provided by Windows (2000, XP, 7). Get the gnu utils to obtain a sed for Windows.

On this site you will find a list of other sed commands to manipulate files.

like image 190
Renze de Waal Avatar answered Oct 18 '25 08:10

Renze de Waal