johng
johng

Reputation: 181

bash sed command failing to find and replace

I can not get the following bash sed commands to find and replace as it fails to match:

$ sed -i.bak 's,\"js/lj.main.min.js\?\d{14}\","js/lj.main.min.js?20130521080532",g' index.html

or

$ sed -i.bak 's,\"js/lj\.main\.min\.js\?\d{14}\","js/lj.main.min.js?20130521080532",g' index.html

On a text file including:

<script src="js/lj.main.min.js?20130520120515"></script>

Should Change to:

<script src="js/lj.main.min.js?20130521080532"></script>

The regex itself works when I try it in http://fiddle.re/m7x56

so whats up?

Upvotes: 1

Views: 240

Answers (1)

choroba
choroba

Reputation: 242373

This expression works for me:

's,"js/lj\.main\.min.\js?[0-9]\{14\}","js/lj.main.min.js?20130521080532",g'

Note that there are many versions of regular expression libraries. Some features (\d) might not be supported, backslashing of some special characters can be different ({}, ? etc.)

Upvotes: 2

Related Questions