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 15
The 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/15
Thanks 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 :-)