Solved how to remove last blank line from a text file

September 7, 2017 at 00:33:24
Specs: Windows 7
how to remove last blank line from a text file
we have used the below command as suggested in this site, but its still not deleting the last line

findstr /v /r/n /c:"^$" /c:"^\ *$" /c:"^\ *$" "C:\Network Table\Filter\File7.txt" >> "File.txt"


See More: how to remove last blank line from a text file

Reply ↓  Report •

✔ Best Answer
September 21, 2017 at 02:48:51
I thought it meant "Remove Last Blank Line From A Text File"

What was I thinkin?

::====== script starts here ===============
:: remove last blank line
:: nolast.bat 2017-09-07 22:43:03.95
@echo off > NEWFILE & setLocal enableDELAYedeXpansioN

set N=
for /f "tokens=1-2 delims=[]" %%a in ('find /n /v "" ^< myfile') do (
if "%%b" equ "" set N=%%a
)

for /f "tokens=1-2 delims=[]" %%a in ('find /n /v "" ^< myfile') do (
if %%a neq !N! echo.%%b
) >> NEWFILE


::====== script ends here =================

=====================

M2 Get custom script or take private lessons



#1
September 7, 2017 at 02:54:37

Reply ↓  Report •

#2
September 7, 2017 at 04:52:11
Hard to glean much from this fruit salad:

findstr /v /r/n /c:"^$" /c:"^\ *$" /c:"^\ *$" "C:\Network Table\Filter\File7.txt" >> "File.txt"

I may help to post a relevant chunk of the file.
2017-09-07 18:50:24.70 GMT +7

=====================

M2 Get custom script or take private lessons


Reply ↓  Report •

#3
September 12, 2017 at 05:41:31
i bet its end of line aka CR LF or "
"
and empty file can be made with batch/cmd like this:

echo.>file.txt

Simple solutions are often the best


Reply ↓  Report •

Related Solutions

#4
September 13, 2017 at 00:50:53
I have no idea what that means but I'll give odds this thread is dead, like many others in the last few nonths.
This forum is having an epidemic of the dumass.
2017-09-13 14:49:38.45 GMT +7

=====================

M2 Get custom script or take private lessons


Reply ↓  Report •

#5
September 18, 2017 at 20:09:41
Mechanix2Go: Hard to glean much from this fruit salad

/v /r/n
Print lines that don't match, with line numbers. /R is redundant since FINDSTR uses its regex engine by default.

/c:"^$"
Matches empty line

/c:"^\ *$"
In theory matches any line with only spaces

/c:"^\ *$"
Repeat of previous switch. Should probably be a tab instead of a space?

How To Ask Questions The Smart Way

message edited by Razor2.3


Reply ↓  Report •

#6
September 21, 2017 at 00:05:30
I know OP has long since left the scene, but the problem was interesting for batch. This attempts to give the line-number of the last line of "data" excluding tabs, spaces, and nuls. Clipping/trimming the file is not addressed since there are various ways and batch is the least dependable:

:: ---- begin snip - blanks.bat
@echo off & setlocal
for /f "tokens=1* delims=[]" %%a in ('find /n /v "" ^<textfile') do (
call :xx %%a %%b
)
echo last line with data: %last%
goto :eof

:xx
if "%2" neq "" set last=%1
:: ---- end


Reply ↓  Report •

#7
September 21, 2017 at 02:48:51
✔ Best Answer
I thought it meant "Remove Last Blank Line From A Text File"

What was I thinkin?

::====== script starts here ===============
:: remove last blank line
:: nolast.bat 2017-09-07 22:43:03.95
@echo off > NEWFILE & setLocal enableDELAYedeXpansioN

set N=
for /f "tokens=1-2 delims=[]" %%a in ('find /n /v "" ^< myfile') do (
if "%%b" equ "" set N=%%a
)

for /f "tokens=1-2 delims=[]" %%a in ('find /n /v "" ^< myfile') do (
if %%a neq !N! echo.%%b
) >> NEWFILE


::====== script ends here =================

=====================

M2 Get custom script or take private lessons


Reply ↓  Report •

Ask Question