Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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.