Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude lines by pattern in sed

Tags:

bash

sed

I'm trying write a sed command in bash that updates all references to javascript and css files in an HTML file with $(name).min.js, however I want to ignore files with the word MANAGER_WIDGET in the path e.g.

Replace:

<script type="text/javascript" src="javascript/scripts.js"/>

But not:

`<script type="text/javascript" src="$MANAGER_WIDGET/Common/API/Plugin.js"/>`

So far I've got the following sed command which adds .min to all files js and css files:

sed "s/\.\([jscss]\+\)\"/\.min\.\1\"/g" index.html

It would be great if someone can show me how I can also exclude lines with MANAGER_WIDGET in them.

like image 968
matt Avatar asked Nov 12 '12 20:11

matt


1 Answers

sed '/MANAGER_WIDGET/!s/\.\([jscss]\+\)\"/\.min\.\1\"/g' index.html
like image 62
ezod Avatar answered Sep 28 '22 02:09

ezod