How to batch editing Material with or with our scripts or plugin?

I have around 400 materials as following


and i want to make them all like below

how may i do it?