Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace string after equal sign

Tags:

sed

I have a XML file with the following structure:

<ns1:ReservationPCC pseudoCityCode="1234" pseudoCityType="Booking" supplierService="Sabre"/>

and I would like to replace the pseudoCityCode by let's say abcd.

I'm trying the following:

sed -e's/pseudoCityCode=.*/pseudoCityCode="abcd" /g'

But, it returns:

<ns1:ReservationPCC pseudoCityCode="abcd"

Adding a white space:

sed -e's/pseudoCityCode=.*\s/pseudoCityCode="abcd" /g'

will return the following:

<ns1:ReservationPCC pseudoCityCode="abcd" supplierService=Sabre/>

Why did the pseudoCityType disappear? What am I missing?

Carlos

like image 852
Carlos Avatar asked Mar 22 '26 02:03

Carlos


1 Answers

sed 's/pseudoCityCode="[^"]*"/pseudoCityCode="abcd"/'<<<'<ns1:ReservationPCC pseudoCityCode="1234" pseudoCityType="Booking" supplierService="Sabre"/>'

or like @Ed Morton said:

sed 's/\(pseudoCityCode="\)[^"]*/\1abcd/'<<<'<ns1:ReservationPCC pseudoCityCode="1234" pseudoCityType="Booking" supplierService="Sabre"/>'
like image 138
tso Avatar answered Mar 25 '26 21:03

tso