I want to parse a css file and multiply each pixel value by (2/3). I was wondering if this was possible with sed? I know this is incorrect syntax but i think it'll bring home the explanation of what i want to achieve:
sed -e "s|\([0-9]*\)px|int((\1 * 2)/3)|g" file.css
So basically I want to take \1, multiply it by (2/3) and cast to and int. Or maybe it's more possible with awk? Suppose I could write a python script, but would like to know if it can be done by quicker means.
Thanks
use awk
$ cat file
foo: 3px; bar: 6px
$ awk '{for(i=1;i<=NF;i++){if($i~/^[0-9]+px/){o=$i;sub(/^[0-9]+/,"",o);$i=($i+0)*(2/3)o}}}1' file
foo: 2px; bar: 4px
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With