Community
    • Login

    Remove columns from a file

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    25 Posts 6 Posters 10.6k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • EkopalypseE
      Ekopalypse
      last edited by Ekopalypse

      @Laurent

      the first thing you need to figure out is what a column is or how it can be detected.
      Without such an information it is nearly impossible to form a proper regex.

      1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @Laurent
        last edited by

        @Laurent

        I guess the idea in general is like this:

        find: (?-s)^(.{4}).{17}
        repl: ${1}

        But as @Ekopalypse , there may be some pitfalls.

        1 Reply Last reply Reply Quote 2
        • guy038G
          guy038
          last edited by guy038

          Hello, @laurent, @ekopalypse, @alan-kilborn, and All

          This S/R should work :

          • SEARCH (?-s)^.{4}\K.{1,18}

          • REPLACE Leave EMPTY

          • Click on the Replace All button, exclusively !

          • If lines have less than 22 characters, each character after position 4 is deleted

          Best Regards,

          guy038

          1 Reply Last reply Reply Quote 2
          • LaurentL
            Laurent
            last edited by

            Thank you all for your replies.

            The command from @Alan-Kilborn is what I was looking for.

            Brilliant, Cheers Alan !

            Alan KilbornA 1 Reply Last reply Reply Quote 1
            • EkopalypseE
              Ekopalypse
              last edited by

              This post is deleted!
              1 Reply Last reply Reply Quote 0
              • Alan KilbornA
                Alan Kilborn @Laurent
                last edited by

                @Laurent

                You could also use the keyboard/mouse to do it, even on a massive file.
                The key to doing it is using the Begin / End Select feature on the Edit menu.

                Here’s how, for example:

                • Move to top-of-file (Ctrl+Home)
                • Move the caret to line 1, column 5.
                • Run Begin / End Select.
                • Move to bottom-of-file (Ctrl+End)
                • Move the caret to line 1, column 22.
                • Press Alt+Shift+right and then Alt+Shift+left (gets you into “column mode”)
                • Run Begin / End Select.

                Your column mode selection should be made across the entire file (it may take some time for the selection to appear if the file is truly on the massive scale).

                1 Reply Last reply Reply Quote 2
                • guy038G
                  guy038
                  last edited by guy038

                  Hi, @laurent, @alan-kilborn and All,

                  @Alan-kilborn, your method can even be simplified :

                  • Left-mouse click at the beginning of the expected rectangular selection

                  • Select the Edit > Begin/End Select menu option ( The option is automatically checked )

                  • Move to the location where the rectangular selection must stop

                  • Hit the ALT key and, simultaneously, left-mouse click, at this end location

                  • Release the ALT key

                  • Select, again, the Edit > Begin/End Select menu option ( The option is automatically unchecked )

                  => A rectangular selection should appear between the columns defined by the two left-mouse clicks ;-))

                  Best Regards,

                  guy038

                  P.S. :

                  It worth to define a shortcut for the Begin/End Select operation ( Line 26 ) in the Shortcut Mapper

                  Alan KilbornA 1 Reply Last reply Reply Quote 1
                  • Alan KilbornA
                    Alan Kilborn @guy038
                    last edited by Alan Kilborn

                    @guy038 said in Remove columns from a file:

                    your method can even be simplified

                    It really isn’t a simplification; it’s just the equivalent way for mouse-junkies.
                    Since most of my time is spent typing text (well, this is a text editor after all), my hands are most often on the keyboard, not the mouse.

                    It worth to define a shortcut for the Begin/End Select operation

                    I agree; my favorite for this is assigning to Ctrl+b


                    NOTE: I had a copy/paste error in my bullet point above; it should have read:

                    • Move the caret to the last line of the file, column 22.
                    1 Reply Last reply Reply Quote 1
                    • LaurentL
                      Laurent
                      last edited by Laurent

                      Thx again all for the follow up, I quite like @guy038 method too => (?-s)^.{4}\K.{1,18}

                      Alan KilbornA 1 Reply Last reply Reply Quote 1
                      • Alan KilbornA
                        Alan Kilborn @Laurent
                        last edited by

                        @Laurent said in Remove columns from a file:

                        I quite like @guy038 method too => (?-s)^.{4}\K.{1,18}

                        It’s a good method, with one limitation: it uses \K which can’t be used with step-by-step Replace and must be used with a blanket Replace All.

                        This is fine, except that often when people are given a cryptic regex that does something, their first inclination is to try and do a one-at-a-time replacement to verify it is working. Then they notice that it isn’t changing their data, and, well, this just makes the confusion grow.

                        I prefer to not use \K in solutions, for this reason, unless it really makes sense to (speeds up execution dramatically – which may be the case, here – or there is no other way of achieving a goal).

                        Of course, @guy038 said to use Replace All, but still…

                        1 Reply Last reply Reply Quote 2
                        • guy038G
                          guy038
                          last edited by guy038

                          Hi, @laurent, @alan-kilborn and All,

                          When I talk about simplification, it’s a great big word !

                          I just meant that we could replace the two shortcuts Alt + Shift+ Left and Alt + Shift+ Right with Alt + Left-mouse click !

                          Cheers,

                          guy038

                          Alan KilbornA 1 Reply Last reply Reply Quote 0
                          • Alan KilbornA
                            Alan Kilborn @guy038
                            last edited by Alan Kilborn

                            @guy038 said in Remove columns from a file:

                            I just meant that we could replace the two shortcuts Alt + Shift+ Left and Alt + Shift+ Right with Alt + Left-mouse click !

                            Still too burdensome, if my hands are on the keyboard. :-)
                            But, in truth, I have a macro for those two combinations anyway plus Begin/End Select, tied to Shift+Ctrl+b.
                            Thus if I’m doing a normal Begin/End Select, I do two Ctrl+b, one at each end of my block.
                            But if I’m intending to do a column version of same, I start it with a Ctrl+b, move to my endpoint, and do Shift+Ctrl+b.

                            Initially, I wanted it to be Shift+Alt+b instead, however, I found that combination will “ring the bell” on my machine, which I found very annoying. It seems to do this because “Alt” is involved. Does anyone know how to prevent this, if it doesn’t just happen to me?

                            PeterJonesP 1 Reply Last reply Reply Quote 2
                            • PeterJonesP
                              PeterJones @Alan Kilborn
                              last edited by PeterJones

                              @Alan-Kilborn said in Remove columns from a file:

                              I wanted it to be Shift+Alt+b instead, however, I found that combination will “ring the bell” on my machine

                              I believe it’s because in most Windows apps, including Notepad++, the Alt+letter or Alt+Shift+letter will try to activate the menu with that accelerator value. If that accelerator doesn’t exist, then it will beep at you.

                              However, when I map the Begin/End Selection to Alt+B and the Macro (Alt+Shift+RightArrow,Alt+Shift+LeftArrow,Being/End Selection) to Alt+Shift+B, the Alt+Shift+B stops ringing the bell.

                              Alan KilbornA 1 Reply Last reply Reply Quote 1
                              • Alan KilbornA
                                Alan Kilborn @PeterJones
                                last edited by

                                @PeterJones said in Remove columns from a file:

                                when I map the Begin/End Selection to Alt+B and the Macro (Alt+Shift+RightArrow,Alt+Shift+LeftArrow,Being/End Selection) to Alt+Shift+B, the Alt+Shift+B stops ringing the bell.

                                That’s interesting.
                                Does that mean that somehow when invoking the Alt+Shift+b, it knows somehow that Alt+b is assigned to some function in Notepad++ (and thus is not an non-existent menu command)?

                                I feel like I want to map Alt+b to nothing (SCI_NULL ?) just so the bell will not ring if I changed my macro to be Shift+Alt+b.
                                I certainly don’t want my Begin / End Select command mapped to Alt+b instead of Ctrl+b – after years of having it on Ctrl+b, it would be hard to get used to. Plus, in my mind, Alt+something IS for dropping a menu, unless combined with Shift as well.

                                PeterJonesP 1 Reply Last reply Reply Quote 1
                                • PeterJonesP
                                  PeterJones @Alan Kilborn
                                  last edited by

                                  @Alan-Kilborn said in Remove columns from a file:

                                  @PeterJones said in Remove columns from a file:

                                  when I map the Begin/End Selection to Alt+B and the Macro (Alt+Shift+RightArrow,Alt+Shift+LeftArrow,Being/End Selection) to Alt+Shift+B, the Alt+Shift+B stops ringing the bell.

                                  That’s interesting.
                                  Does that mean that somehow when invoking the Alt+Shift+b, it knows somehow that Alt+b is assigned to some function in Notepad++ (and thus is not an non-existent menu command)?

                                  Nope. I unassigned Begin/End Selection, and left Alt+Shift+B on the macro, and Alt+Shift+B still didn’t ring the bell.

                                  I also verified that using the macro to both Begin and End the column selection worked. Since I don’t have the years of training on Ctrl+B, I might just train myself to Alt+Shift+B for begin and end column selection. :-)

                                  Alan KilbornA 1 Reply Last reply Reply Quote 1
                                  • Alan KilbornA
                                    Alan Kilborn @PeterJones
                                    last edited by

                                    @PeterJones said in Remove columns from a file:

                                    I also verified that using the macro to both Begin and End the column selection worked

                                    I never thought of “starting” that way, but yes, it should and does work.
                                    Nice one!

                                    Nope. I unassigned Begin/End Selection, and left Alt+Shift+B on the macro, and Alt+Shift+B still didn’t ring the bell.

                                    Something sounds suspicious about this…
                                    Does it remain after a restart?

                                    PeterJonesP 1 Reply Last reply Reply Quote 0
                                    • PeterJonesP
                                      PeterJones @Alan Kilborn
                                      last edited by PeterJones

                                      @Alan-Kilborn said in Remove columns from a file:

                                      Something sounds suspicious about this…
                                      Does it remain after a restart?

                                      It remains after a restart of Notepad++, yes.

                                      I unzipped a fresh Notepad++, ran it, and verified that Alt+Shift+B beeps at me. Then I assigned the normal Begin/End Selection to Alt+Shift+B. From that moment on, it stopped beeping at me. Even if I restarted that fresh instance. If I go into a different program’s window (say, notepad.exe) and Alt+Shift+B, it will beep at me because of no such accelerator.

                                      As far as I can tell, I don’t need to have ever assigned Alt+B to make Alt+Shift+B stop beeping.

                                      Edit: and if I un-assign Alt+Shift+B in either instance of Notepad++, it starts beeping at me again.

                                      Alan KilbornA 1 Reply Last reply Reply Quote 1
                                      • Alan KilbornA
                                        Alan Kilborn @PeterJones
                                        last edited by

                                        @PeterJones

                                        Okay, I will have to do some more trials with the “beeping” thing…

                                        While we’re on the topic of Begin/End Select … it is a great feature only missing one thing: Some type of visual indication that the “begin” has been done and the “end” is what is pending. Any agreement on that?

                                        PeterJonesP 1 Reply Last reply Reply Quote 1
                                        • PeterJonesP
                                          PeterJones @Alan Kilborn
                                          last edited by

                                          @Alan-Kilborn said in Remove columns from a file:

                                          Any agreement on that?

                                          ++ I would be much more likely to train myself to use that feature – both in normal and column select modes – if I had such a status indicator.

                                          Given that Scott recently updated the selection status section of the status bar, he might be convinced to add the Begin/End Selection state there, if someone were to suggest it to him.

                                          Alan KilbornA 1 Reply Last reply Reply Quote 1
                                          • Alan KilbornA
                                            Alan Kilborn @PeterJones
                                            last edited by Alan Kilborn

                                            @PeterJones

                                            My first thought was status bar as well, but in observing some of the “issue” discussion, there seems to be some opposition by the devs to ever altering what it shows.

                                            I guess I mean by adding new fields; I have seen recent tweaks to the status bar for showing the current position – which is great for me as a PythonScript programmer, BTW – but some people have requested Zoom level on the status bar, which I find reasonable, and have been shot down, presumably because it would be a brand-new thing?

                                            As an alternate to status bar, would it be reasonable to perhaps invert the colors of the line number margin, for example, in between “begin” and “end” select? I suppose not everyone has that margin turned on, although I find that unfathomable.

                                            Uh oh, I think I just found a bug with Begin/End Select. It doesn’t restrict itself to the active tab – if you begin a select in one tab and end it in another, you get interesting results! :-)

                                            1 Reply Last reply Reply Quote 3
                                            • First post
                                              Last post
                                            The Community of users of the Notepad++ text editor.
                                            Powered by NodeBB | Contributors