Replace the space between 2 numbers with a slash
-
Hello
I have a textfile with numbers in two columns. in the first column is ID number and in the second column is subnumber to the ID. However, not every ID has a sub-number. The problem now is that I have to replace the spaces between the ID and the sub-number with a /. Where there is no sub-number, no / should be created. With search & replace you can replace all spaces with a /, but that doesn’t help me. Unfortunately I can’t find a quick and easy solution. Maybe someone can help me.I can create a few lines with the commands \b ^ $ {n,m}, but I always get an error.
Example
440 4 1727 671 1 458 40 3 909 2 64 49 1 1906 628 1 2560 1521 1522 1523 2633 15The Results should look like this
440/4 1727 671/1 458 40/3 909/2 64 49/1 1906 628/1 2560 1521 1522 1523 2633/15Thanks so much for help
-
@Thomas-Klinghan said in Replace the space between 2 numbers with a slash:
I’d try:
Find:
(\d+)\h+(\d+)
Replace:$1/$2
Search mode: Regular expressionand then use the command to remove leading whitespace from all of the lines.
LATER EDIT: added forgotten
/between $1 and $2. :-)
I can create a few lines with the commands \b ^ $ {n,m}, but I always get an error.
I’ve no idea at all what that means.
-
My solution is a bit different from @Alan-Kilborn , for one I do insert the
/character as requested (not now that he has adjusted his regex). I also noted the lines with only the first number had additional spaces behind which appear to have been removed, so my regex also does that.Find What:
(?-s)(\d+)\x20+(\d+)?
Replace With:${1}(?{2}/${2})Terry
-
@Terry-R said in Replace the space between 2 numbers with a slash:
My solution is a bit different from
Yea, Terry has a pretty good solution here.
Aside from forgetting the/(for some reason I thought this was a replace-multiple-space-with-one-space problem), I also didn’t notice trailing spaces (I didn’t copy the data, I just visually inspected it). -
@Alan-Kilborn said in Replace the space between 2 numbers with a slash:
LATER EDIT: added forgotten / between $1 and $2. :-)
it works :-)
Thanks -
@Terry-R nice, it works, thanks :-)
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