How to delete every second line?

How to delete every second line?

5
NewbieNewbie
5

    Nov 27, 2006#1

    Does anyone have any ideas how to do this automatically?

    6,686585
    Grand MasterGrand Master
    6,686585

      Nov 27, 2006#2

      A "simple" regular expression replace can do it:

      In UltraEdit style:

      Find What: %^(*^p^)*^p
      Replace With: ^1

      In Unix/Perl style:

      Find What: ^(.*\p).*\p
      Replace With: \1

      Because of ^p or \p this works only for files with DOS line terminations (CR+LF). See in help of UE/UES the pages Find command or Replace command and Regular Expressions to understand it.
      Best regards from an UC/UE/UES for Windows user from Austria

      5
      NewbieNewbie
      5

        Nov 28, 2006#3

        Thanks, works perfectly, expect that the last line doesn't remove but it's easy to remove. :)

        How about:
        • Remove every last/first line?
        • Remove every third line?
        • Duplicate every line?

        344
        MasterMaster
        344

          Nov 28, 2006#4

          The last line should always have a crlf to work properly.
          1.: Use "TOP", "BOTTOM" and "DELETELINE" in an UE macro to do this job.
          2.: Also a UE macro with key arrow down + deleteline + "EOF loop". Easy.
          3.: Also a trivial UE macro with arrow down and duplicateline.

          Bego
          Normally using all newest english version incl. each hotfix. Win 10 64 bit

          5
          NewbieNewbie
          5

            Nov 28, 2006#5

            Thanks, Bego. But I don't get any of your advice working.  :?

            Is it possible to do these with the 'regular expression' feature?

            344
            MasterMaster
            344

              Nov 29, 2006#6

              No. regexps are good for "inLINE-searching/replacing", not for navigating in a file.

              Try this:
              Create a macro called "delTopBottom"
              Paste in those lines:

              Code: Select all

              HexOff
              Top
              DeleteLine
              Bottom
              DeleteLine
              Let it run on your example file. It should do your issue no. 1

              rds Bego
              Normally using all newest english version incl. each hotfix. Win 10 64 bit

              5
              NewbieNewbie
              5

                Nov 29, 2006#7

                Thanks once again, Bego. But it's not even works now. :?

                I figured out these which can do only at the top of the document also 'Play macro to End of File' have to use:

                1. Remove every last/first line

                Code: Select all

                HexOff
                Key DOWN ARROW
                DeleteLine
                2. Remove every third line

                Code: Select all

                HexOff
                Key DOWN ARROW
                Key DOWN ARROW
                DeleteLine
                3. Duplicate every line (does not works - does not duplicate first line and the macro loops infinitely :?)

                Code: Select all

                HexOff
                Key DOWN ARROW
                DupeLine

                5
                NewbieNewbie
                5

                  How to delete every second line in a text file?

                  Dec 05, 2008#8

                  It's a small macro that is supposed to delete every second line in a file but stalls in the beginning.

                  Code: Select all

                  InsertMode
                  ColumnModeOff
                  HexOff
                  Top
                  Loop 0
                  MoveLineDown
                  MoveLineDown
                  DeleteLine
                  ExitLoop
                  EndLoop
                  Top
                  What have I missed?

                  6,686585
                  Grand MasterGrand Master
                  6,686585

                    Re: How to delete every second line in a text file?

                    Dec 05, 2008#9

                    The command MoveLineDown does not only move the cursor down, it moves the entire line down. And you exit your endless loop after deleting 1 line because ExitLoop is inside the loop without any condition.

                    You don't really need a macro for that job because a single regular expression replace can do that too. However, here is the macro.

                    InsertMode
                    ColumnModeOff
                    HexOff
                    UnixReOff
                    Bottom
                    IfColNumGt 1
                    "
                    "
                    IfColNumGt 1
                    DeleteToStartofLine
                    EndIf
                    EndIf
                    Top
                    Find RegExp "%^(*^r++^n^)*^r++^n"
                    Replace All "^1"

                    This macro should work for files with DOS or UNIX line terminations, but definitely not for MAC files.
                    Best regards from an UC/UE/UES for Windows user from Austria

                    5
                    NewbieNewbie
                    5

                      Re: How to delete every second line in a text file?

                      Dec 05, 2008#10

                      Ohh man, I can't believe how complicated a macro that turned out to be 8O

                      Thanks Mofi!

                      Keywords for others: remove delete every 2nd other line macro script