Replacing HTML tag content using sed

后端 未结 3 1456
孤独总比滥情好
孤独总比滥情好 2020-12-18 00:41

I\'m trying to replace the content of some HTML tags in an HTML page using sed in a bash script. For some reason I\'m not getting the proper result as it\'s not replacing an

3条回答
  •  没有蜡笔的小新
    2020-12-18 00:46

    sed -i -e 's%([0-9]*)/'"${unlockedCount}/g" index.html 
    

    I removed the Useless Use of Cat, took out a bunch of unnecessary backslashes, added single quotes around the regex to protect it from shell expansion, and fixed the repetition operator. You might still need to backslash the grouping parentheses; my sed, at least, wants \(...\).

    Note the use of single and double quotes next to each other. Single quotes protect against shell expansion, so you can't use them around "${unlockedCount}" where you do want the shell to interpolate the variable.

提交回复
热议问题