I'm new in bash script and trying to replace some words in my file using sed. Following is the bash I use in my script:
sed -i '' "s/<pre>.*<\/pre>/<pre>($NEWNAME) $MD5<\/pre>/"~/Desktop/replace.html
And I got error message saying: bad flag in substitute command: 'U'
. I use double quote because I need to put variables in.
My environment is Mac.
======================================
1.Turns out I forgot to leave a space between replace string and file name. Which led to the result always showing: bad flag in substitute command: '~'
. It works now.
2.The reason is I used MD5=$(md5 path)
to create MD5 value which gets the reault of MD5 (path) *****
, and the path contains /
which breaks the regex. After changing MD5=$(md5 -q path)
, it will be ok.
Most likely your $NEWNAME
variable has a forward slash in it, which is being used as regex delimiter in sed
. Try this sed
with an alternate delimiter e.g. ~
:
sed -i '' "s~<pre>.*</pre>~<pre>($NEWNAME) $MD5</pre>~" ~/Desktop/replace.html
Collected from the Internet
Please contact javaer1[email protected] to delete if infringement.
Comments