Reputation: 97
I have a file "test.xml" That looks like the below:
CLASS="BAKERS"
GROUP="ABCYYYYY"
TRACK="DASD"
OWNERS="ALPHA"
GROUP="ABCXXXXX"
GROUP="ABCZZZZZ"
I want to use a single SED line command to find all occurrences of GROUP="ABC
Then within the "" I want add suffix: _DONE
to all the matches found.
So the result should look like:
CLASS="BAKERS"
GROUP="ABCYYYYY_DONE"
TRACK="DASD"
OWNERS="ALPHA"
GROUP="ABCXXXXX_DONE"
GROUP="ABCZZZZZ_DONE"
This is the command I am using:
`sed -i.bkp '/^GROUP="ABC/ s/$/_DONE"/' test.xml`
but it is appending after the " and not within the ""
Upvotes: 2
Views: 258
Reputation: 345
Use this:
sed -i.bkp 's/GROUP="ABC[A-Z]*/&_DONE/g' test.xml
I tested with your example and worked.
Upvotes: 0
Reputation: 5092
You can use this sed command
sed '/GROUP="ABC/s/\(.*\)"/\1_DONE"/'
Output :
CLASS="BAKERS"
GROUP="ABCYYYYY_DONE"
TRACK="DASD"
OWNERS="ALPHA"
GROUP="ABCXXXXX_DONE"
GROUP="ABCZZZZZ_DONE"
Upvotes: 1
Reputation: 185254
Try doing this but without the backticks :
sed -i.bak '/^GROUP="ABC/s/"$/_DONE"/' file
Upvotes: 1
Reputation: 16556
It's almost that. But $
means end of line so you have to substitute the last "
using "$
instead:
sed -i.bkp '/^GROUP="ABC/ s/"$/_DONE"/' test.xml
you could also specify that there is some blank after the "
with for instance "[ \t]*$
Upvotes: 2