> ./replace.sh > new-b.js
> diff -u b.js new-b.js
--- b.js 2013-04-22 17:52:11.756024531 +0800
+++ new-b.js 2013-04-22 17:58:32.828017570 +0800
@@ -2,7 +2,7 @@
document.write('foo bar');
document.write('</div>');
// new code
-var a = 'foo.js';
-document.write('<script id="foo" src="' + a + '"></script>');
+var a = 'bar.js', stamp = +new Date() + '=';
+document.write('<script id="foo" src="' + a + '?' + stamp + '"></script>');
// other code
document.write('<div> other text</div>');
-
-
Save ldong/7663280c82e2d4791840 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// many many codes | |
document.write('foo bar'); | |
document.write('</div>'); | |
// new code | |
var a = 'bar.js', stamp = +new Date() + '='; | |
document.write('<script id="foo" src="' + a + '?' + stamp + '"></script>'); | |
// other code | |
document.write('<div> other text</div>'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// many many codes | |
document.write('foo bar'); | |
document.write('</div>'); | |
// new code | |
var a = 'foo.js'; | |
document.write('<script id="foo" src="' + a + '"></script>'); | |
// other code | |
document.write('<div> other text</div>'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
sed -n ' | |
/^document.write(\'<\/div>\')/ { | |
n | |
:start | |
/id="foo"/! { | |
N | |
b start | |
} | |
p | |
} | |
' a.js | sed ' | |
/^document.write(\'<\/div>\')/ { | |
n | |
:start | |
/id="foo"/! { | |
N | |
b start | |
} | |
r /dev/stdin | |
d | |
} | |
' b.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment