0

I have a bash script that generates an xml file (drivers_list.xml) and has to subsequently remove this line:

xmlns="http://feed.elasticstats.com/schema/nascar/series-v2.0.xsd"

By looking around this page I found some suggestions and attempted,

sed -i '' "s/xmlns=\"http://feed.elasticstats.com/schema/nascar/series-v2.0.xsd\"//g" drivers_list.xml

Unfortunately, when I run it, I get the following error:

sed: 1: "s/xmlns="http://feed.el ...": bad flag in substitute command: 'f'

How can I fix this?

2
  • 1
    some thing wrong with the pattern split character in the search string or replace string. in your case, you could use # instead of / as pattern split character, so it didn't need to escape the / in search or replace string, like sed "s#original_string_without_she#new_string_without_she#/g" drivers_list.xml. Commented Jun 21, 2021 at 1:48
  • welcome to SO, one more thing as the same, you could use single quote ' instead of double quote " to contain the s/regexp/replacement/, so you didn't need to escape the " in the pattern string, because your pattern string didn't contain the ' in this case. I can't find the pattern split character with English link, I only found a Chinese link(blog.chinaunix.net/uid-12072359-id-2960859.html), maybe you could understand it by translator. Commented Jun 21, 2021 at 2:28

2 Answers 2

1

You have to escape all slashes(/) and use two types of quotes(',"):

sed -i 's/xmlns=\"http:\/\/feed.elasticstats.com\/schema\/nascar\/series-v2.0.xsd\"//g' drivers_list.xml

Then the output should be as expected.
Of course, with this approach you will not catch the xmlns='...' definitions - which are equally valid.

Sign up to request clarification or add additional context in comments.

1 Comment

You have to escape all slashes(/) it make no sense, you could use other pattern split character such as # / ,, so it didn't need to escape the character which not equal the pattern split character.
0

Find it -- Delimiters in sed substitution

Sed can use any character as a delimiter. 
In fact, it will automatically use the character following the `s` as a delimiter.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.