joesatch
joesatch

Reputation: 137

sed/awk how to add to the matched strings

I have text file which contains lines as mentioned below

<property>PASSWORD_X_1</property>
<property>PASSWORD_A_2</property>
<property>PASSWORD_B_6</property>

so on so forth..

Now i am looking to change the lines to:

<property>{PASSWORD_X_1}</property>
<property>{PASSWORD_A_2}</property>
<property>{PASSWORD_B_6}</property>

I could change the initial "{" using simple sed expression:

sed -e '/PASSWORD/{PASSWORD/g'

Not able to figure out how do i append the "}" character.

Any suggestions..?

J

Upvotes: 1

Views: 245

Answers (4)

Tedee12345
Tedee12345

Reputation: 1210

awk '{sub(">P",">{P") sub("</","}</");}1' file

Upvotes: 0

potong
potong

Reputation: 58351

This might work for you:

sed 's/PASSWORD[^<]*/{&}/' file

Upvotes: 0

Chisholm
Chisholm

Reputation: 1076

This should work:

awk -F"<|>" '{ print "<" $2 ">{" $3 "}<" $4 ">" }' file.text

Upvotes: 2

dav1d
dav1d

Reputation: 6055

sed -e 's/PASSWORD_[A-Z]_[0-9]/{&}/'

easy to modify!

Upvotes: 2

Related Questions