0

I have text that looks like this

HELLO WORLD (some_text, some_other_text)

I want to append a number say 16 at the end to the above text like this

HELLO WORLD (some_text, some_other_text) 16

I know this regex ^HELLO WORLD \(([a-z],[a-z]) matches it . I am not sure how to store the regex matched in a variable and then append 16 to it.

newfurniturey
  • 35,828
  • 9
  • 90
  • 101
jhon.smith
  • 1,865
  • 5
  • 25
  • 44
  • 3
    What's the context in which this sed script will be run? [What are you REALLY trying to achieve?](http://mywiki.wooledge.org/XyProblem) – ghoti Nov 01 '12 at 03:45

1 Answers1

7

The & character holds everything in the pattern space:

sed 's/^HELLO WORLD ([a-z_]*, [a-z_]*)/& 16/' file

Take a look at Using & as the matched string

And Using \1 to keep part of the pattern

Steve
  • 45,652
  • 12
  • 89
  • 100