Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a list of pixel values in a file, and need each to be half its current value. The pattern for the value is always 123px where 123 varies drastically.

How can I half each pixel value?
I'm guessing sed will be helpful.

share|improve this question

1 Answer 1

I would suggest you use awk instead of sed.

If your input file file.dat contains one entry per line this will work:

$ awk '{ print $1/2"px"}' file.dat

If you need more sophisticated math use gawk instead of awk.

share|improve this answer
    
Looking into the awk docs now, but each value has exists on a line with other info and another value, like this (it's CSS): .sprite-v16 { background-position: -462px -2002px; } –  tbeseda May 13 '11 at 20:16
    
This is more complicated than your question made it seem. While looking around I came across issociate.de/board/post/461416/Math_in_sed/…, but it needs some adijustments for your case. Since CSS can contain simple calculations you could just replace ps by *0.5px for the time being: sed 's/px/\*0\.5px/g'. –  Benjamin Bannier May 14 '11 at 13:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.