sed replace append character match pattern case insensitive

Problem:
replace Date to _Date in text in file:

 <xs:attribute name="Date" type="xs:date" />

to get:

<xs:attribute name="_Date" type="xs:date" />

Solution:
sed -i 's/name="\(Date\)"/name="_\1"/gI' file
t=date && sed -i "s/name=\"\($t\)\"/name=\"_\1\"/gI" file

where:
gI means replace globally case insensitive
\1 means matched date within: name=”Date”

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s