How to replace a whole line with sed?

Michael picture Michael · Jan 11, 2012 · Viewed 300.3k times · Source

Suppose I have a file with lines

aaa=bbb

Now I would like to replace them with:

aaa=xxx

I can do that as follows:

sed "s/aaa=bbb/aaa=xxx/g"

Now I have a file with a few lines as follows:

aaa=bbb
aaa=ccc
aaa=ddd
aaa=[something else]

How can I replace all this lines aaa=[something] with aaa=xxx using sed?

Answer

John Doyle picture John Doyle · Jan 11, 2012

Try this:

sed "s/aaa=.*/aaa=xxx/g"