Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Suppose I want to append two digit numbers in my file with "some_thing".

Like from this:

12 23 45


12_something 23_something 45_something

How can I do this using regular expression replacement?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

& is the whole match, so just use &_something in the substitute operation.

share|improve this answer
Thanks, it works! – xiaohan2012 May 10 '12 at 3:35
Is there a difference between using & and \0? – Bernhard May 10 '12 at 5:38
@Bernhard: not according to sub-replace-special, except varying by the magic option. – Ignacio Vazquez-Abrams May 10 '12 at 5:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.