Feng
Feng

Reputation: 41

replace text in a line based on specified pattern using sed in bash

I have trouble to replace the text inside a line using sed. here is the example.

<con:startTransactionRequestElement>2a07a832-5b4e-44d2-8826-64d8678f6226</con:startTransactionRequestElement>

i want to only change the content between <con:startTransactionRequestElement> and </con:startTransactionRequestElement> for example, change the above content to below:

<con:startTransactionRequestElement>abcdefegeawge</con:startTransactionRequestElement>

can someone tell me how to do that?

Thanks.

Upvotes: 2

Views: 63

Answers (1)

Cyrus
Cyrus

Reputation: 88553

With GNU sed:

sed 's|\(<con:startTransactionRequestElement>\).*\(</con:startTransactionRequestElement>\)|\1abcdefegeawge\2|' file

If you want to edit your file "in place" use sed's option -i.

Upvotes: 3

Related Questions