Trim length between two characters
-
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,8This is what it should look like after
#,61007954426,1
#,20530009986,1
#,65433455333,5
#,20530002200,1
#,3360,20
#,71810326785,2
#,67764334775,8Thank you
-
-
Perfect thank you very much.
-
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.
-
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”).
-
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,8Here 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 expressionsearch mode -
Click, exclusively, on the
Replace Allbutton
And, we would obtain the expected result :
#,61007954426,1 #,20530009986,1 #,65433455333,5 #,20530002200,1 #,3360,20 #,71810326785,2 #,67764334775,8Best Regards,
guy038
-
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login