Deleting blank line doesn't work for last line

Deleting blank line doesn't work for last line

121
Basic UserBasic User
121

    Aug 04, 2018#1

    If my page consists of:

    1 ...

    3 ...
    4
    5


    ^p$ will get rid of lines 2 and 4, but it won't get rid of line 5. Is there a good way to get rid of a last blank line?

    11327
    MasterMaster
    11327

      Aug 04, 2018#2

      Something like Perl RegExp:

      ^\r\n|\r\n(?![\w\W])
      It's impossible to lead us astray for we don't care even to choose the way.

      6,675585
      Grand MasterGrand Master
      6,675585

        Aug 04, 2018#3

        UltraEdit and Unix regular expression engines do not interpret end of file as end of line on using $. This behavior is unmodified since I am using UltraEdit for Windows (20 years).

        The Perl regular expression engine interprets $ as end of line and as end of character stream and for that reason also as end of file.

        Technical a string at end of a file not ending with a line termination is not really a line, it is just a string at end of file.

        See also Remove / delete blank and empty lines.
        Best regards from an UC/UE/UES for Windows user from Austria

        121
        Basic UserBasic User
        121

          Aug 04, 2018#4

          Mofi, that had some great info. However, NONE of the Perl regex codes worked for me. If it helps to know, my txt files are ANSI - Latin 1 encoded.

          Ovg's code worked. However, after reading through your link, I figured out that I could accomplish this with as little as:

          \r\n$

          6,675585
          Grand MasterGrand Master
          6,675585

            Aug 04, 2018#5

            Well, all the regular expressions posted by me in referenced post are for deleting empty or blank lines within a file. None of them is for deleting the line termination at end of file.

            Let us look on your example stored in text file with DOS/Windows line endings with enabled View - Show line endings (traditional menu) or checked Line endings on ribbon tab View:

            ...

            ...


            The file has just 4 lines each ending with carriage return + line-feed. It is possible to position the caret at end of file which is at beginning of "line" five to append something at end of file. My regular expressions are for deleting empty and blank lines from file. So they produce:

            ...
            ...

            The file has just two lines after storing the modification. But it is again possible to position the caret at end of file which is at beginning of "line" three to append something here.

            What you wanted to achieve is:

            ...
            ...

            So the file contains now only one line with three dots terminated with carriage return + line-feed and three dots at end of file with no line terminating characters. This is possible for nearly all text files, but quite often cause troubles, especially if a programmer does not take into account this special case of no carriage return/line-feed at end of file.
            Best regards from an UC/UE/UES for Windows user from Austria