I have been bashing my head against the wall trying to get sed to search a file are replace a timestamp.
example replace strings (file):
<script src="<@ofbizContentUrl>/xxx/js/v6/jsfile.js?v=201711271300</@ofbizContentUrl>"></script>
<script src="<@ofbizContentUrl>/xxx/js/v6/jsfile2.js?v=20171127245</@ofbizContentUrl>"></script>
basically I want to replace the 201711271300 in the examples with the current timestamp which i have saved in a variable date. The dates in the example differ from case to case.
I've been trying
sudo sed -i "s/?v=.+?(?=<)/?v=${date}/g" file
to no avail, going on 2 hours now
Try this one
sed "s/?v=\([0-9]*<\)/?v=${date}</g" $file
It uses a simpler pattern: all digits until you hit a <
. Replace by a data (and restore the <
).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.