tl;dr
I want to add a 0
at the end of the first backreference (\1
) from a grep search. How can I differentiate this from the tenth backreference (\10
).
Using grep in bbedit, I want to replace a part of a string with a part of that part of a string and a zero.
For example, find and replace this part of a string:
195.22.126.x
in this string:
195.22.126.x - - [13/Jul/2018:19:16:49 -0200] "GET /file.txt HTTP/1.1" 301 243
with part of that part of a string and a zero:
195.22.126.0
If I wanted to replace the "x" at the end of that part of a string with a "y", the grep code would look like this:
Find:
^(\d+\.\d+\.\d+\.)x
Replace:
\1y
But if I want to replace the "x" with a "0" (zero), the program tries to extract the tenth match, instead of appending a zero to the first match, because \10
looks like "tenth match" to it, not like "first match and a zero".
So how do I append a zero to a grep match?
Please note that I cannot simply replace "x" with "0", because there are other "x"s in the string. Therefore I have to match the correct part of the string.