Take the 2-minute tour ×
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

to

12_something 23_something 45_something

How can I do this using regular expression replacement?

share|improve this question
add comment

1 Answer

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
2  
@Bernhard: not according to sub-replace-special, except varying by the magic option. –  Ignacio Vazquez-Abrams May 10 '12 at 5:40
add comment

Your Answer

 
discard

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.