mysql - Using awk on sql database to change all iframe "width" and "height" sizes -


i have wordpress database thousands of posts in it. need regex , awk command go through database (after mysql dump it) , change sizes uniform size width="600" height="350"

currently looks this:

some paragraph text here, description [tab:short code here] <iframe width="200" height="180" src="https://www.youtube.com/embed/ad4grqxzpfg" frameborder="0" allowfullscreen></iframe> [tab:different short code here] <iframe src="http://other-videohost.com/embed-ksq9vn3gwc16.html" frameborder=0 marginwidth=0 marginheight=0 scrolling=no width=250 height=300></iframe> 

result in database should this:

some paragraph text here, description [tab:short code here] <iframe width="600" height="350" src="https://www.youtube.com/embed/ad4grqxzpfg" frameborder="0" allowfullscreen></iframe> [tab:different short code here] <iframe src="http://other-videohost.com/embed-ksq9vn3gwc16.html" frameborder=0 marginwidth=0 marginheight=0 scrolling=no width=600 height=350></iframe> 

so additional information:

i'm going dump database mysqldump run successful command regex change target pattern without affecting images or other elements not iframes. fine target iframes since iframes used on site video embeds.

the server running wordpress on ubuntu 14.04

take notice width , height in cases behind src , in others in front of src such in example. want make non-case-sensitive.

suggestions , solutions welcome. thank guys.

with gnu awk gensub() , word boundaries (\<):

$ awk -v w=600 -v h=350 -v ignorecase=1 '{       $0 = gensub(/\<(width="?)[0-9]+("?)/,"\\1"w"\\2","g")       $0 = gensub(/\<(height="?)[0-9]+("?)/,"\\1"h"\\2","g")   } 1' file paragraph text here, description [tab:short code here] <iframe width="600" height="350" src="https://www.youtube.com/embed/ad4grqxzpfg" frameborder="0" allowfullscreen></iframe> [tab:different short code here] <iframe src="http://other-videohost.com/embed-ksq9vn3gwc16.html" frameborder=0 marginwidth=0 marginheight=0 scrolling=no width=600 height=350></iframe> 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -