computing
  • 4

Delete Last Empty Line Of Text File

  • 4

Hi,
I have text file with 1 or 2 empty line on the last. I need a batch script to delete the last (1 or 2) empty line
for example :
tiger
dog
cat
mouse
empty line
empty line

After run the script, it should be
tiger
dog
cat
mouse
the last empty line will be removed.
Please advice. Thanks a lot
Alex.

Share

1 Answer

  1. I could not duplicate the error on my xp, so I’m not sure. maybe there’s something in one of those last lines… but you could try this:

    for /f “tokens=*” %%a in (textfil) do >>noblanks echo.%%a

    although I doubt that will resolve the issue. You might need to PM your file (or a close facsimile) to me so I can try it. I tried it with both a space, and a null (char. zero), and still didn’t get the junk. worst case, try this:

    for /f “tokens=*” %%a in (textfil) do if “%%a” neq “” >>noblanks echo.%%a

    • 0