Skip to content

Instantly share code, notes, and snippets.

@ldong
Forked from netwjx/a.js
Last active August 29, 2015 14:20
Show Gist options
  • Save ldong/7663280c82e2d4791840 to your computer and use it in GitHub Desktop.
Save ldong/7663280c82e2d4791840 to your computer and use it in GitHub Desktop.
// 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>');
// 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>');
> ./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>');
#!/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