I need to perform search and replace using sed. starting from this sample text for example :
<TextView
android:textSize="20.0sp"
android:textStyle="bold"
android:textColor="@android:color/white"
android:layout_gravity="center"
android:textColor="@android:color/white"
i wanna replace all occurrences of android:textColor="@android:color/white"
with android:textColor="#ffff5d"
I spent over 3 hours (yes so frustrating) without success the closer I get is
sed -i "s/"$android:textColor=\"@android:color/white\""\|"$android:textColor=\"#ff4000\""/g" path to file.xml
but it's far from right. as results is
androidwhite"|:textColor="#ff4000"/white"
what am I doing wrong?
sed
code, which probably shouldn't be there. You have an unquoted$android
, which the shell probably expands to an empty string. And you didn't quote the slash incolor/white
. Suggestions: To quote the $, use single quotes, and to avoid having to quote slashes, use a different character to separate regular expression from substitution; for examplesed 's|android:textColor="@android:color/white"|android:textColor="#ffff5d"|g'
. And as @Kusalananda says,sed
is normally not the right tool for processing XML.