Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Trim length between two characters

    Help wanted · · · – – – · · ·
    4
    6
    374
    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.
    • Sean
      Sean last edited by

      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

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

        @Sean

        You might try:

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

        1 Reply Last reply Reply Quote 1
        • Sean
          Sean last edited by Sean

          @Alan-Kilborn

          Perfect thank you very much.

          1 Reply Last reply Reply Quote 1
          • Steven Haymes
            Steven Haymes last edited by Steven Haymes

            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.

            Alan Kilborn 1 Reply Last reply Reply Quote 1
            • Alan Kilborn
              Alan Kilborn @Steven Haymes last edited by

              @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
              • guy038
                guy038 last edited by

                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
                • First post
                  Last post
                Copyright © 2014 NodeBB Forums | Contributors