I would like to use Vim to match a regular expression and perform a substitution. I have a tsv file with lines that look like this:
rs11223-A -A
rs23300-G -TTA
rs9733-T -G
rs11900000-GT -TTG
I wish to substitute the dash (-) character for a tab only in the first column after the rs...
In Vim I was attempting to perform the substitution using:
:%s/(?<=^rs[0-9]{1,12})-/\t/g
Could anyone point out what my problem is and a correct solution?
It may be dependent on configuration, but in my environment I have to prepend { , }
with \
.
Also, Vim has \zs
and \ze
to start and end matching, so you usually don't have to deal with normal regex lookaround.
This does what you want:
:%s/^rs\d\{1,12}\zs-/\t/g
Positive look behind is done using:
\@<=
So you could use something like:
:%s/\d\@<=-/\t/g
Your actual data may be more complex, but with what you posted you could also just settle for:
:%s/-/\t
If rs
should be at the beginning of the line, you can use \zs
to specify the start of the match and use anchoring (^
):
:%s/^rs\d*\zs-/\t
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With