• Login
Community
  • Login

Trim length between two characters

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
6 Posts 4 Posters 769 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.
  • S
    Sean
    last edited by Jul 15, 2019, 4:49 PM

    What I need to do is trim the last character between the , and , if the length is 12 or greater which would then make the length 11.

    This is before

    #,610079544260,1
    #,205300099864,1
    #,65433455333,5
    #,205300022008,1
    #,3360,20
    #,718103267854,2
    #,67764334775,8

    This is what it should look like after

    #,61007954426,1
    #,20530009986,1
    #,65433455333,5
    #,20530002200,1
    #,3360,20
    #,71810326785,2
    #,67764334775,8

    Thank you

    A 1 Reply Last reply Jul 15, 2019, 5:05 PM Reply Quote 0
    • A
      Alan Kilborn @Sean
      last edited by Jul 15, 2019, 5:05 PM

      @Sean

      You might try:

      Find: ^(#,\d{11})\d(?=,)
      Replace: \1
      Search mode: Regular expression

      1 Reply Last reply Reply Quote 1
      • S
        Sean
        last edited by Sean Jul 15, 2019, 5:11 PM Jul 15, 2019, 5:10 PM

        @Alan-Kilborn

        Perfect thank you very much.

        1 Reply Last reply Reply Quote 1
        • S
          Steven Haymes
          last edited by Steven Haymes Jul 15, 2019, 8:27 PM Jul 15, 2019, 8:26 PM

          If the file is not too long, you can always use Column Mode with the Alt key. I do similar operations on CSV files all the time. Regular expressions are more elegant though.

          A 1 Reply Last reply Jul 15, 2019, 9:10 PM Reply Quote 1
          • A
            Alan Kilborn @Steven Haymes
            last edited by Jul 15, 2019, 9:10 PM

            @Steven-Haymes

            I made the assumption that the OP may have other lines (that are longer) intermingled with the ones shown that he doesn’t want affected. Otherwise, yes, you are right, this is a good application of column mode editing, perhaps in combination with the Begin/End Select command, which also works with column mode editing, although it is a bit obscure (you have to get into column mode as you are positioning the caret for the “end select”).

            1 Reply Last reply Reply Quote 1
            • G
              guy038
              last edited by Jul 15, 2019, 10:13 PM

              Hello, @sean, @alan-kilborn, @steven-haymes, and All,

              I’m afraid that, in order to use the column mode, in a reliable way, we should align the comma symbols, padding preceding positions with spaces chars !

              So, this time, the regex solution seems to be more secure ;-))

              For instance, with that sample text, below :

              #,6100795442608787,1
              #,205300099864,1
              #,65433455333,5
              #,20530002200815618844,1
              #,3360,20
              #,718103267854,2
              #,67764334775,8
              

              Here is a regex S/R which deletes any non-null range of digits, after the 11th, till the second comma of each line :

              • SEARCH ^#,\d{11}\K\d+(?=,)

              • REPLACE Leave EMPTY

              • Tick the Wrap around

              • Select the Regular expression search mode

              • Click, exclusively, on the Replace All button

              And, we would obtain the expected result :

              #,61007954426,1
              #,20530009986,1
              #,65433455333,5
              #,20530002200,1
              #,3360,20
              #,71810326785,2
              #,67764334775,8
              

              Best Regards,

              guy038

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